js验证手机号、密码、短信验证码代码工具类
本文实例为大家分享了js验证手机号、密码、短信验证码的代码工具类,供大家参考,具体内容如下
代码工具类
/**
*参数较验
*
**/
varverification={
stop:false,//倒计时
//验证手机号
phone:function(tel,id){
if(""==tel||!tel){
mui.toast('手机号不可以为空!');
}else{
varreg=/^0?1[3|4|5|7|8][0-9]\d{8}$/;
//验证规则
if(reg.test(tel))returntrue;
mui.toast("手机号错误!");
}
document.getElementById(id).focus();
returnfalse;
},
//验证密码(密码只能由数字和字母组成)
password:function(w,id){
if(""==w||!w){
mui.toast('请输入密码!');
}elseif(w.length<6){
mui.toast('密码至少大于等于6位!');
}elseif(w.length>20){
mui.toast('密码不能超过20位!');
}elseif(w){
varreg=/^[0-9a-zA-Z]+$/;
if(reg.test(w))returntrue;
mui.toast("密码只能由数字和字母组成");
}
document.getElementById(id).focus();
returnfalse;
},
//验证码倒计时
code:function(tel,btn,type){
varthat=this,
tel=$.trim(tel);
if(!this.phone(tel,'userTel'))returnfalse;
if(true==that.stop)returnfalse;//防止重复点击
that.stop=true;
varbtn=$("#"+btn);
btn.attr("disabled",true).text("正在发送");
var_no=60;
vartime=setInterval(function(){
_no--;
btn.text(_no+"秒后重发");
if(_no==0){
//btn.attr("disabled",false).text("获取验证码");
btn.removeAttr('disabled').text("重新获取验证码");
that.stop=false;
_no=60;
clearInterval(time);
}
},1000);
varurl="/Home/User/sendVerifyCode.html";
$.post(url,{
toNumber:tel,
type:type
},function(result){
mui.toast(result.info);
if(200!=result.status){
btn.removeAttr('disabled').text("获取验证码");
that.stop=false;
_no=60;
clearInterval(time);
}
},'json');
}
};
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。