1.
<script src="../JS/jquery-3.2.0.js" type="text/javascript" ></script> <script src="../JS/bootstrap.min.js"></script> <link type="text/css" rel="stylesheet" href="../css/bootstrap.min.css" /> <body> <div class="form-group"> <label class="col-sm-2 control-label font">手机号</label> <div class="col-sm-10 "> <input type="text" class="form-control bt" name="tel" id="tel" placeholder="可用于登录" ><span id="sj"></span> </div> </div><br/><br/><br/> </body>
2.
<script>function checkMobile(str) { var re = /^1\d{10}$/ if (re.test(str)) { $("#sj").html("手机号码格式正确"); $("#sj").css("color","green"); } else { $("#sj").html("手机号码格式错误"); $("#sj").css("color","red"); } } $("#tel").blur(function(){ var str = $(this).val(); checkMobile(str); })</script>
时间: 2024-10-12 13:14:35