温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-09-02 05:14:33 来源:脚本之家 阅读:178 作者:Joker_Ye 栏目:web开发

本文实例为大家分享了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("disabled", true).text("正在发送"); 
    var _no = 60; 
    var time = 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); 
 
    var url = "/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'); 
  } 
}; 

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI