Common JS Verification

Source: Internet
Author: User

/*
Check whether the username is composed of letters, numbers, and underscores (_) and has a length of 6 to 20 characters.
Output prompt information to the label with the ID of info
*/
Function checkname (){
VaR infotext = "";
VaR rename =/^/W {6, 20} $ /;
VaR username = Document. getelementbyid ("username"). value;
If (! Rename. Test (username ))
{// When the username format is incorrect
Infotext + = username + "Incorrect username format <br> ";
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}

}
/*
Check whether the password is composed of letters, numbers, and underscores (_) and has 6 to 20 characters in length.
Output prompt information to the label with the ID of info
*/
Function checkpwd (){
VaR infotext = "";
VaR repwd =/^ [0-9a-za-z] {6, 20} $ /;
VaR pass = Document. getelementbyid ("password"). value;
If (! Repwd. Test (PASS ))
{// Confirm that the password is inconsistent with the password
Infotext + = pass + "Incorrect password format <br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}
/*
Check whether the two passwords are consistent
Output prompt information to the label with the ID of info
*/
Function checkpwdok (){
VaR infotext = "";
VaR pass = Document. getelementbyid ("password"). value;
VaR passok = Document. getelementbyid ("passwordok"). value;
If (pass! = Passok)
{// Confirm that the password is inconsistent with the password
Infotext + = pass + "inconsistent passwords" + passok + "<br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}
/*
Check the email format
Output prompt information to the label with the ID of info
*/
Function checkemail (){
VaR infotext = "";
VaR e_mail = Document. getelementbyid ("email"). value;
VaR Re =/^/W + ([-+.] /W +) * @/W + ([-.] /W + )*/. /W + ([-.] /W +) * $ /;
If (! Re. Test (e_mail ))
{// Incorrect email format
Infotext + = e_mail + "Incorrect email format <br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}
/*
(At submit) check whether the user name, password, and email address are empty
Output prompt information to the label with the ID of info
*/
Function OK _onclick (){
VaR username = Document. getelementbyid ("username"). value;
VaR pass = Document. getelementbyid ("password"). value;
VaR e_mail = Document. getelementbyid ("email"). value;
VaR infotext = "";

If (username = "")
{// When the user name is empty
Infotext + = "the user name cannot be blank <br> ";
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
If (pass = "")
{// When the password is empty
Infotext + = "the password cannot be blank <br> ";
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
If (e_mail = "")
{// When the mailbox is empty
Infotext + = "email cannot be blank <br> ";
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Return true;
}
// ------------------------------------------ Additional ----------------------------------------
/*
Check whether the phone number is in the correct format: 0451-1234567, 010-12345678, and 0451-12345678
Output prompt information to the label with the ID of info
*/
Function checkphone (){
VaR infotext = "";
VaR phone = Document. getelementbyid ("phone"). value;
VaR Re =/^/d {3}-/d {8} |/d {4}-/d {7,8} $ /;
If (! Re. Test (phone ))
{// Incorrect phone format
Infotext + = phone + "Incorrect phone format <br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}
/*
Check the ID card format of 15 and 18 digits
Output prompt information to the label with the ID of info
*/
Function checkidcard (){
VaR infotext = "";
VaR idcard = Document. getelementbyid ("idcardnum"). value; // ID
VaR cardleibie = Document. getelementbyid ("zhengjian"). value; // credential category
VaR reidcard =/^/d {15} |/d {18} $/; // The regular code of the ID card
VaR reqita =/^/D * $/; // Regular Expression of other ID numbers: 0 or any number
If (cardleibie = "shenfenzheng "){
If (! Reidcard. Test (idcard ))
{// Incorrect ID card format
Infotext + = idcard + "Incorrect ID card number format <br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}
If (cardleibie = "qita "){
If (! Reqita. Test (idcard ))
{// The format of other certificates is incorrect
Infotext + = idcard + "Incorrect ID Number Format <br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}
}
/*
Check the QQ format from 10000 to 999999999
Output prompt information to the label with the ID of info
*/
Function checkqq (){
VaR infotext = "";
VaR QQ = Document. getelementbyid ("QQ"). value;
VaR Re =/^ [1-9] [0-9] {4, 8} $ /;
If (! Re. Test (qq ))
{// Incorrect QQ format
Infotext + = QQ + "Incorrect QQ format <br>"
Document. getelementbyid ("info"). innerhtml = infotext;
Return false;
}
Else {
Document. getelementbyid ("info"). innerhtml = "";
Return true;
}
}

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.