js Verification Mobile Phone Number Password SMS Verification Code Tool Class
- 2021-07-13 03:56:56
- OfStack
In this paper, we share the code tools for js to verify mobile phone number, password and SMS verification code for your reference. The specific contents are as follows
Code tool class
/**
* Parameter comparison
*
* */
var verification = {
stop : false, // Countdown
// Verify the mobile phone number
phone : function (tel, id) {
if ("" == tel || !tel) {
mui.toast(' Mobile phone number cannot be empty !');
} else {
var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
// Verification rule
if (reg.test(tel)) return true;
mui.toast(" Wrong mobile phone number !");
}
document.getElementById(id).focus();
return false;
},
// Verify password ( Passwords can only consist of numbers and letters )
password : function (w, id) {
if ("" == w || !w) {
mui.toast(' Please enter your password !');
} else if (w.length < 6) {
mui.toast(' Password is at least greater than or equal to 6 Bit !');
} else if (w.length > 20) {
mui.toast(' Password cannot exceed 20 Bit !');
} else if (w) {
var reg = /^[0-9a-zA-Z]+$/;
if (reg.test(w)) return true;
mui.toast(" Passwords can only consist of numbers and letters ");
}
document.getElementById(id).focus();
return false;
},
// Verification code countdown
code : function (tel, btn, type) {
var that = this,
tel = $.trim(tel);
if (!this.phone(tel, 'userTel')) return false;
if (true == that.stop) return false; // Prevent repeated clicks
that.stop = true;
var btn = $("#"+btn);
btn.attr("disabled", true).text(" Sending ");
var _no = 60;
var time = setInterval(function () {
_no--;
btn.text(_no + " Retransmitted in seconds ");
if (_no == 0) {
//btn.attr("disabled", false).text(" Get verification code ");
btn.removeAttr('disabled').text(" Retrieve the verification code ");
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(" Get verification code ");
that.stop = false;
_no = 60;
clearInterval(time);
}
}, 'json');
}
};