JavaScript regular form verification (user name, password, confirmation password, mobile phone number, landline number, social Security number)

Source: Internet
Author: User

1, about the JavaScript form verification, if the use of bidirectional binding front-end JS frame, it will be much easier. But bloggers still suggest that you do not leave the source JS itself. Because the source of JS is the kingly way.

Attention:

A, error message in the code may not be found in the code, "error. jpg" IMAGE, make a

b, the validation of the judgment has been completed, only need to be based on their own validation rules to form validation, replace their regular expression.

C, the blogger error message image inserted in this document. It needs to be renamed "error. jpg" and is placed under the HTML root directory.

(Error message picture)

<! DOCTYPE html>//User Name Verificationdocument.form1.username.onkeyup=function(){        varreg=/^[a-za-z]{1}[a-z|a-z|0-9]{5,29}/; if(Reg.test ( This. Value) && This.value.length>=6&& This. value.length<=30) {document.getElementById ("Namemsg"). innerhtml= "Input correct"; }Else{document.getElementById ("Namemsg"). Innerhtml= " '; }     }     //Password Verificationdocument.form1.pwd.onkeyup=function(){        varreg1=/[a-za-z]+[0-9]+/; if(Reg1.test ( This. Value) && This.value.length>=6&& This. value.length<=8) {document.getElementById ("Pwdmsg"). innerhtml= "Input correct"; }Else{document.getElementById ("Pwdmsg"). Innerhtml= " '; }     }     //Confirm Passworddocument.form1.pwd1.onkeyup=function(){         if( This.value==document.form1.pwd.value&& This. value!= "") {document.getElementById ("Pwd1msg"). innerhtml= "Input correct"; }Else{document.getElementById ("Pwd1msg"). Innerhtml= " '; }     }     //Mobile phone number verificationdocument.form1.phone.onkeyup=function(){         varreg2=/^ (13|14|15|17|18) [0-9]{9}/; if(Reg2.test ( This. Value) && This. value.length==11) {document.getElementById ("Iphone1"). innerhtml= "Input correct"; }Else{document.getElementById ("Iphone1"). Innerhtml= " '; }       }     //Phone number Verificationdocument.form1.phone1.onkeyup=function(){         varreg3=/^[0-9]{3,4} (\-{1}) [0-9]{7,8}/; if(Reg3.test ( This. Value) && This. value.length==13| | This. value.length==12) {document.getElementById ("Iphone2"). innerhtml= "Input correct"; }Else{document.getElementById ("Iphone2"). Innerhtml= " '; }     }     //Identification Number Verificationdocument.form1.sfzid.onkeyup=function(){         varreg4=/^\d{17}[(0-9) | X|x]{1}/; if(Reg4.test ( This. Value) && This. value.length==18) {document.getElementById ("Sfzmsg"). innerhtml= "Input correct"; }Else{document.getElementById ("Sfzmsg"). Innerhtml= " '; }     }     //Register Button Method     functionTest () {varstr= "Input Correct"if(document.getElementById ("namemsg"). innerhtml!==str) {document.getElementById ("Namemsg"). Innerhtml= " ';            Document.form1.username.focus (); Document.form1.username.value=""; return false; }         if(document.getElementById ("pwdmsg"). innerhtml!==str) {document.getElementById ("Pwdmsg"). Innerhtml= " ';            Document.form1.pwd.focus (); Document.form1.pwd.value=""; return false; }         if(document.getElementById ("pwd1msg"). innerhtml!==str) {document.getElementById ("Pwd1msg"). Innerhtml= " ';            Document.form1.pwd1.focus (); Document.form1.pwd1.value=""; return false; }         if(document.getElementById ("iphone1"). innerhtml!==str) {document.getElementById ("Iphone1"). Innerhtml= " ';            Document.form1.phone.focus (); Document.form1.phone.value=""; return false; }         if(document.getElementById ("Iphone2"). innerhtml!==str) {document.getElementById ("Iphone2"). Innerhtml= " ';            Document.form1.phone1.focus (); Document.form1.phone.value=""; return false; }     }   </script></body>

JavaScript regular form verification (user name, password, confirmation password, mobile phone number, landline number, social Security number)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.