溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

js驗證手機號、密碼、短信驗證碼代碼工具類

發(fā)布時間:2020-09-02 05:14:33 來源:腳本之家 閱讀:194 作者:Joker_Ye 欄目:web開發(fā)

本文實例為大家分享了js驗證手機號、密碼、短信驗證碼的代碼工具類,供大家參考,具體內容如下

代碼工具類

/** 
 * 參數(shù)較驗 
 * 
 * */ 
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}$/; 
      //驗證規(guī)則 
      if (reg.test(tel)) return true; 
      mui.toast("手機號錯誤!"); 
    } 
    document.getElementById(id).focus(); 
    return false; 
  }, 
 
  //驗證密碼(密碼只能由數(shù)字和字母組成) 
  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("密碼只能由數(shù)字和字母組成"); 
    } 
    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("正在發(fā)送"); 
    var _no = 60; 
    var time = setInterval(function () { 
      _no--; 
      btn.text(_no + "秒后重發(fā)"); 
      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問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI