/*
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;
}
}