JS判断手机号是否符合、手机验证码接收效果
JS判断手机号是否符合、手机验证码接收效果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="js/jquery-1.8.3.min.js" type="text/javascript"></script> </head> <body> <form method="post" action=""> <li> <p>手机号码<span></span></p> <input type="text" class="textForm" name="mobilephone" id='mobilephone'/> </li> <li> <p>手机验证码</p> <input type="text" class="textForm02" id='code' name='code'> <input type='button' value='免费获取验证码' onclick='time(this)'/> </li> <br/> <li><input type="submit" class="btn03" value="立即找回" id="loginCommit"/></li> </form> <script type="text/javascript"> var wait = 60; function time(btn) { var mobilephone = $("#mobilephone").val(); var patrnPhone = /^(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$/; if (!patrnPhone.test(mobilephone)) {alert('手机号码格式不正确,请确认后在输入');return;}; btn.removeAttribute("disabled"); if (wait == 60) { $.post("./mobile_validate_code", { "mobile": mobilephone }, function(data){ }, "json"); } if (wait == 0) { btn.removeAttribute("disabled"); btn.value = "免费获取验证码"; wait = 60; } else { btn.setAttribute("disabled", true); btn.value = wait + "秒后重新获取验证码"; wait--; setTimeout(function () { time(btn); }, 1000) } } </script> </body> </html> |
Read more