<Script Language = "JavaScript">
Function formCheck (){
If (document. forms [0]. userName. value = ""){
Alert ("Enter your user name! ");
Document. forms [0]. userName. focus ();
Return false;
}
Var filter =/^ s * [A-Za-z0-9] {6, 20} s * $ /;
If (! Filter. test (document. forms [0]. userName. value )){
Alert ("the username is incorrect. Please enter it again! The available characters are (A-Z a-z 0-9) no less than 6 characters, no more than 20 characters, be sure not to use spaces. ");
Document. forms [0]. userName. focus ();
Document. forms [0]. userName. select ();
Return false;
}
If (document. forms [0]. password. value = ""){
Alert ("enter your password! ");
Document. forms [0]. password. focus ();
Return false;
}
Var filter =/^ s * [A-Za-z0-9] {6, 20} s * $ /;
If (! Filter. test (document. forms [0]. password. value )){
Alert ("the password is incorrect. Please enter it again! The available characters are (A-Z a-z 0-9) no less than 6 characters, no more than 20 characters, be sure not to use spaces. ");
Document. forms [0]. password. focus ();
Document. forms [0]. password. select ();
Return false;
}
If (document. forms [0]. pwd. value = ""){
Alert ("enter your password! ");
Document. forms [0]. pwd. focus ();
Return false;
}
If (document. forms [0]. password. value! = Document. forms [0]. pwd. value ){
Alert ("the two passwords are inconsistent. Please enter them again! ");
Document. forms [0]. password. focus ();
Document. forms [0]. password. select ();
Return false;
}
If (document. forms [0]. name. value = ""){
Alert ("Enter your real name! ");
Document. forms [0]. name. focus ();
Return false;
}
Var patrn =/^ [\ u0391-\ uFFE5] {2, 4} $/; // judge whether the regular expression is Chinese
If (! Patrn. test (document. forms [0]. name. value )){
Alert ("Enter your real name, 2-4 Chinese characters! ");
Document. forms [0]. name. focus ();
Document. forms [0]. name. select ();
Return false;
}
If (document. forms [0]. age. value = ""){
Alert ("Enter your age! ");
Document. forms [0]. age. focus ();
Return false;
}
Var number =/^ [0-9] {1, 3} $ /;
If (! Number. test (document. forms [0]. age. value )){
Alert ("Enter your age (must be a number )! ");
Document. forms [0]. age. focus ();
Return false;
}
If (document. forms [0]. stature. value = ""){
Alert ("Enter your height! ");
Document. forms [0]. stature. focus ();
Return false;
}
Var stature =/^ [0-9] {1, 3} $ /;
If (! Stature. test (document. forms [0]. stature. value )){
Alert ("Enter your height (must be a number )! ");
Document. forms [0]. stature. focus ();
Return false;
}
If (document. forms [0]. tel. value = ""){
Alert ("Please enter your contact number! ");
Document. forms [0]. tel. focus ();
Return false;
}
Var tel =/(^ ([0] [1-9] {2, 3} [-])? \ D {3, 8} (-\ d {1, 6 })? $) | (^ \ ([0] [1-9] {2, 3} \) \ d {3, 8} (\ d {1, 6 }\))? $) | (^ \ D {3, 8} $) | (^ [1] [3] [0-9] {9} $) | (^ 0 [1] [3] [0-9] {9} $ )/;
If (! Tel. test (document. forms [0]. tel. value )){
Alert ("enter the correct phone number (mobile phone number )! ");
Return false;
}
If (document. forms [0]. mail. value = ""){
Alert ("Enter your email! ");
Document. forms [0]. mail. focus ();
Return false;
}
Var mail =/^ ([-_ A-Za-z0-9 \.] +) @ ([_ A-Za-z0-9] + \.) + [A-Za-z0-9] {2, 3} $ /;
If (! Mail. test (document. forms [0]. mail. value )){
Alert ("the email format is incorrect. Please enter it again! ");
Document. forms [0]. mail. focus ();
Document. forms [0]. mail. select ();
Return false;
}
If (document. forms [0]. school. value = ""){
Alert ("Enter your school! ");
Document. forms [0]. school. focus ();
Return false;
}
Var school =/^ [\ u0391-\ uFFE5] {1, 20} $ /;
If (! School. test (document. forms [0]. school. value )){
Alert ("Enter your school (Chinese characters required )! ");
Document. forms [0]. school. focus ();
Document. forms [0]. school. select ();
Return false;
}
Return true;
}
</Script>
Submit Form:
<Form action = "#" method = "post" onsubmit = "return formCheck ()">
Note:
Document. forms [0]. userName. forms [0] in value is the first form in Your webpage, and so on; userName is the name of the text box (<input type = "text" name = "userName" value = ""> );