登录注册校验

window.οnlοad=function(){

        //获取手机输入框
    var tel=$("#tel");
    //获取验证码输入框
    var code=$("#code");
    //获取密码输入框
    var pwd=$("#pwd");
    //获取发送验证码按钮
    var send=$("#send");
    //获取注册按钮
    var btn=$("#btn");
    var tip=$("#tip");
    var timer=null;

    var now=60;

//发送验证码接口请求
   send.click(function(){
        var regtel=/^1[3|4|5|7|8]\d{9}$/; 
        var telval=tel.val();
        if(telval==""){
            tip.html("手机号码不能为空");
            tip.css("opacity",1);
            setTimeout(function(){
                tip.css("opacity",0);
            },2000)
        }else if(!regtel.test(telval)){
            tip.html("手机号码格式不正确");
            tip.css("opacity",1);
            setTimeout(function(){
                tip.css("opacity",0);
            },2000)
        }else{
            $.ajax({
                      type:"post",
                      url:"/sendSmsForSpread.do",
                      data:{
                         tel:telval
                      },
                      dataType:"json",
                      success:function(res){
                              if(res.code==200){
                                    tip.html(res.msg);
                                   
                                    timer=setInterval(function(){
                                         if(now!=0){
                                              send.val(now); 
                                              now--;
                                              send.attr("disabled",true);
                                         }else{
                                              clearInterval(timer);
                                              send.attr("disabled",false);
                                              send.val("重新发送");
                                              now=60;
                                         } 
                                    },1000)
                            }else if(res.code==500){
                                  tip.html(res.msg);
                                  tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
                            }
                    }
              })
        }

   })

function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
//注册接口
    btn.click(function(){
             var regpwd=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
             var regtel=/^1[3|4|5|7|8]\d{9}$/; 
             var telval=tel.val();
             var codeval=code.val();
             var pwdval=pwd.val();
             var url=window.location.href;
             var userChannel="";
             if(url.indexOf("?")==-1){
            tip.html("不能注册");
                 tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
             }else{
//              userChannel =url.split("?")[1].split("=")[1];
            userChannel =GetQueryString("code");
             }
             
            if(telval==""){
                 tip.html("手机号码不能为空");
                 tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
            }else if(!regtel.test(telval)){
                 tip.html("手机号码格式不正确");
                 tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
            }else if(codeval==""){
                 tip.html("请输入短信验证码");
                 tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
            }else if(pwdval==""){
                 tip.html("请输入密码");
                 tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
            }else if(!regpwd.test(pwdval)){
                 tip.html("密码格式不正确");
                 tip.css("opacity",1);
                                  setTimeout(function(){
                                      tip.css("opacity",0);
                                  },2000)
            }else{
                 $.ajax({
                      type:"post",
                      url:"/registerReviewForSpread.do",
                      data:{
                         userAccount:telval,
                         userPassword:pwdval,
                         phoneCode:codeval,
                         userChannel:userChannel
                        // userChannel:
                      },
                      dataType:"json",
                      success:function(res){
                          if(res.code==500){
                             tip.html(res.msg);
                             tip.css("opacity",1);
                             setTimeout(function(){
                                   tip.css("opacity",0);
                             },2000)
                          }else if(res.code==200){
                          if(!!window.TuiaAdverter) { //先判断 js 是否引入成功
                          TuiaAdverter.init(function() {
                        window.location.href="/activity/spreadAPP/success.html";
                          })
                          }else{
                          window.location.href="/activity/spreadAPP/success.html";
                          }  
                          }
                  }
               })
            }
    })
   var top=document.getElementById("top");
   top.addEventListener("touchend",function(){
       $("body,html").animate({
          scrollTop:"984px"
       },400)
 })
   var top1=document.getElementById("top1");
   top1.addEventListener("touchend",function(){
       $("body,html").animate({
          scrollTop:"984px"
       },400)
 })
 var top2=document.getElementById("top2");
   top2.addEventListener("touchend",function(){
       $("body,html").animate({
          scrollTop:"984px"
       },400)

 })

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值