Code
// VaR Reg =/^ (\ D +) | ([A-Z] +) $/g filters out one or more numbers from the beginning to the end, or one or more 26 letters
// VaR reg2 =/^ [\ u4e00-\ u9f5a] + $/g; filter out one or more Chinese characters from the beginning to the end.
// VaR reg3 =/^ \ D {1, 3} $/g; filter numbers ranging from 1 to 3
// VaR reg4 =/(^ \ s +) | (\ s + $)/g; select one or more spaces from the beginning to the end.
// Username. Replace (reg4, ""); replace the filtered space with null, that is, remove the space.
// VaR reg5 =/^ \ D {3, 4}-\ D {7, 8} $/g; select the phone number format from the beginning to the end, ranging from 123-1234567 to the longest 1234-12345678
// VaR reg6 =/(\ D +) | ([A-Z] +) @ (\ D +) | ([A-Z] + )). ([A-Z] {3 }$)/g; filter the email format of the copy.
Function Zhuce (){
VaR Username = Document. getelementbyid ( " Username " ). Value;
VaR Realname = Document. getelementbyid ( " Realname " ). Value;
VaR Age = Document. getelementbyid ( " Age " ). Value;
VaR Tel = Document. getelementbyid ( " Tel " ). Value;
VaR Email = Document. getelementbyid ( " Email " ). Value;
VaR Reg = / ^ (\ D +) | ([A-Z] +) $ / G;
VaR Reg2 = / ^ [\ U4e00-\ u9f5a] + $ / G;
VaR Reg3 = / ^ \ D {1, 3} $ / G;
VaR Reg4 = / (^ \ S +) | (\ s + $) / G;
VaR Reg5 = / ^ \ D {3, 4}-\ D {7, 8} $ / G;
VaR Reg6 = / (\ D +) | ([A-Z] +) @ (\ D +) | ([A-Z] + )). ([A-Z] {3} $) / G;
If (Username = "" )
{
Alert ( " Login account cannot be blank " );
Document. getelementbyid ( " Username " ). Focus ();
Return ;
}
If ( ! Reg. Test (username ))
{
Alert (username + " The Logon account can only contain numbers or letters. " );
Document. getelementbyid ( " Username " ). Focus ();
Return ;
}
If (Reg4.test (username ))
{
Alert (username + " The login account contains spaces and is being removed automatically " );
Username = Username. Replace (reg4, "" );
Alert ( " Input " + Username + " . " );
Document. getelementbyid ( " Username " ). Select ();
Return ;
}
If ( ! Reg2.test (realname ))
{
Alert (realname + " The real name must be in Chinese " );
Document. getelementbyid ( " Realname " ). Focus ();
Return ;
}
If ( ! Reg3.test (AGE ))
{
Alert (age + " The age must be a number and cannot exceed 3 digits. " );
Document. getelementbyid ( " Age " ). Focus ();
Return ;
}
If ( ! Reg5.test (TEL ))
{
Alert (Tel + " Incorrect Phone Number Format " );
Document. getelementbyid ( " Tel " ). Focus ();
Return ;
}
If ( ! Reg6.test (email ))
{
Alert (email + " The email format is incorrect. " );
Document. getelementbyid ( " Email " ). Focus ();
Return ;
}
}