微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

js验证手机号、密码、短信验证码代码工具类

本文实例为大家分享了js验证手机号、密码、短信验证码的代码工具类,供大家参考,具体内容如下

代码工具类

rush:js;"> /** * 参数较验 * * */ var verification = { stop : false,//倒计时 //验证手机号 phone : function (tel,id) { if ("" == tel || !tel) { mui.toast('手机号不可以为空!'); } else { var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/; //验证规则 if (reg.test(tel)) return true; mui.toast("手机号错误!"); } document.getElementById(id).focus(); return false; },//验证密码(密码只能由数字和字母组成) password : function (w,id) { if ("" == w || !w) { mui.toast('请输入密码!'); } else if (w.length < 6) { mui.toast('密码至少大于等于6位!'); } else if (w.length > 20) { mui.toast('密码不能超过20位!'); } else if (w) { var reg = /^[0-9a-zA-Z]+$/; if (reg.test(w)) return true; mui.toast("密码只能由数字和字母组成"); } document.getElementById(id).focus(); return false; },//验证码倒计时 code : function (tel,btn,type) { var that = this,tel = $.trim(tel); if (!this.phone(tel,'userTel')) return false; if (true == that.stop) return false; //防止重复点击 that.stop = true;
var btn = $("#"+btn); 
btn.attr("<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>abled",true).text("正在发送"); 
var _no = 60; 
var time = setInterval(function () { 
  _no--; 
  btn.text(_no + "秒后重发"); 
  if (_no == 0) { 
    //btn.attr("<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>abled",false).text("<a href="https://www.jb51.cc/tag/huoqu/" target="_blank" class="keywords">获取</a>验证码"); 
    btn.removeAttr('<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>abled').text("重新<a href="https://www.jb51.cc/tag/huoqu/" target="_blank" class="keywords">获取</a>验证码"); 
    that.stop = false; 
    _no = 60; 
    clearInterval(time); 
  } 
},1000); 

var url = "/Home/User/sendVerifyCode.html"; 
$.post(url,{ 
  toNumber: tel,type:type 
},function (result) { 
  mui.toast(result.info); 
  if (200 != result.status) { 
    btn.removeAttr('<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>abled').text("<a href="https://www.jb51.cc/tag/huoqu/" target="_blank" class="keywords">获取</a>验证码"); 
    that.stop = false; 
    _no = 60; 
    clearInterval(time); 
  } 
},'json'); 

}
};

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐