jQuery 移动端页面手机号+验证码+密码

<div class="swiper-slide">
	<div class="baodanall">
	<div class="baodaninfo">
		<div class="baodan">
			<label class="mui-icon mui-icon-contact"></label>
			<input type="text" id="phone" placeholder="请输入手机号"/>
		</div>
		<div class="baodan">
			<label class="mui-icon mui-icon-info"></label>
			<input class="yzm" type="text" placeholder="请输入验证码"/>
			<button class="yanzhengma" style="">获取验证码</button>
		</div>
		<div class="baodan">
			<label class="mui-icon mui-icon-locked"></label>
			<input type="text" id="password" placeholder="请输入6-16位数字或字母"/>
		</div>
		<!--注册按钮-->
		<div id="zhuce" align="center" style="background-color: white;">
			<button type="button" id="code-btn" class="mui-btn mui-btn-blue mui-btn-block">注册</button>
		</div>
		<!--用户注册协议-->
		<div style="margin-top: 5px;">
			<button style="color: #929292;" type="button" class="mui-btn mui-btn-link">
				注册即同意 <a href="#" style="color: #46abef;">用户注册协议</a>
			</button>
		</div>
	</div>
 </div>
</div>

js部分

<script type="text/javascript">
//    获取验证码
    $(".yanzhengma").on("tap",function(){
        var code = "";//接收验证码
        var count = 60;
        var phone = $("#phone").val();//手机号码 
        var reg = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
        if(!reg.exec(phone) || phone == null || phone == ''){
            mui.toast('手机号输入错误',{duration:'short',type:'div'});
            return false;
        }
        $(".yanzhengma").attr('disabled','disabled');
        $(".yanzhengma").html("倒计时" + count + "秒");
        var timer = setInterval(function(){
            count--;
            $(".yanzhengma").attr('disabled','disabled');
            $(".yanzhengma").html("倒计时" + count + "秒");
            if(count == 0){
                clearInterval(timer);
                $(".yanzhengma").attr("disabled",false);
                $(".yanzhengma").html("重新发送");
                code = "";
            }
        },1000);
    });
    
    $("#code-btn").on("tap",function(){
        var phone = $("#phone").val();//手机号码 
        var reg = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
        var pswd = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
        if(!reg.exec(phone) || phone == null || phone == ''){
            mui.toast('手机号输入错误',{duration:'short',type:'div'});
            return false;
        }else if(!pswd.exec($("#password").val()) || $("#password").val() == null || $("#password").val() == ''){
            mui.toast('密码格式输入错误',{duration:'short',type:'div'});
            return false;
        }else{
            getSrceenWH();
            $('#dialogBg').fadeIn(300);
            $('#dialog').fadeIn();
        }
    })
</script>

猜你喜欢

转载自blog.csdn.net/qq_40001322/article/details/81188147