手机验证码前台jsp校验

验证手机号的正则表达式

<p><label>手机号:</label><input type="text" name="phone" id="phone" value="" placeholder="请输入手机号码"/></p>
<p>
<input type="text" name="yanzhengma" id="yanzhengma" value="" placeholder="请输入验证码"/>
<input type="hidden" id="yanzheng">
<input type="button" name="huoquYanzhengma" id="huoquYanzhengma" value="获取验证码"/>
</p>

$("#huoquYanzhengma").click(function(){
if($("#phone").val()==""||$("#phone").val()==null){
    $("#tishi").show();
    $("#YGTp").text("请输入手机号!");
    return false;
}else{
    var myreg = /^1[3|4|5|7|8][0-9]\d{4,8}$/; //手机号校验
    if(!myreg.test($("#phone").val())) { 
        $("#tishi").show();
        $("#YGTp").text("请填写 有效的手机号码!");
        return; 
    }
}

定时器:输入手机号之后显示60秒倒计时

settime($(‘#huoquYanzhengma’));
var countdown=60;
function settime(val) {
if(countdown == 0){
val.attr(“disabled”,false);
val.val(“重新发送”);
countdown = 60;
}else{
val.attr(“disabled”, true);
val.val(“重新发送(” + countdown + “)”);
countdown–;
setTimeout(function() {
settime(val);
},1000);
}
}

猜你喜欢

转载自blog.csdn.net/jovi_zhao/article/details/78051565