Form login regular verification test()

code show as below:




var regPhone = document.getElementById("regPhone");//Mobile phone number
var regPassword = document.getElementById("regPassword");//Password
var textPhone = document.getElementById("textPhone");//Mobile phone number text prompt box
var textPassword = document.getElementById("textPassword");//Password text prompt box
var forms = document.getElementById("forms");//Form

//Regular expression
var reg1 = /^1\d{10} KaTeX parse error: Undefined control sequence: \W at position 40:… reg2 = /^[\̲W̲\da-zA-Z]{6,20} /;// Password 6-20 numbers, letters, any characters

//Check
var n1 = false,
n2 = false;

//When the phone number box gets the focus
regPhone.onfocus = function(){ // alert("Get the focus"); textPhone.innerHTML = "Please enter the correct 11-digit phone number"; textPhone.style.color = " green"; } //When the phone number box loses focus regPhone.onblur = function(){ if(this.value ==''){ textPhone.innerHTML = "The input content cannot be empty"; textPhone.style.color = "Red"; }else if(!reg1.test(this.value)){ textPhone.innerHTML = "Please enter the correct 11-digit mobile phone number"; textPhone.style.color = "red"; }else{ textPhone.innerHTML = "The format is correct"; textPhone.style.color = "green"; return n1 = true;//The test method is to return true/false }
















}
//When the password box gets the focus
regPassword.onfocus = function(){ textPassword.innerHTML = "Please enter 6-20 digits, letters, and any characters"; textPassword.style.color = "green"; }


//When the password box loses focus
regPassword.onblur = function(){ if(this.value == ""){ textPassword.innerHTML = "Password cannot be empty"; textPassword.style.color = "red"; }else if(!reg2.test(this.value)){ textPassword.innerHTML = "Please enter 6-20 digits, letters, any characters"; textPassword.style.color = "red"; }else{ textPassword.innerHTML = " The information is correct"; textPassword.style.color = "green"; return n2 =true; } }











//form form
forms.onsubmit = function(){ // regular expression judgment var regs = !reg1.test(regPhone.value)||!reg2.test(regPassword.value); //variable judgment var regs = n1



n2 false ||false;
// console.log(regs);
if(!regs == false){ alert("The information you filled in is wrong!"); return false; }else{ alert("The information is filled in correctly"); return true ; } }






Guess you like

Origin blog.csdn.net/weixin_43465609/article/details/109272665