// Method. obtain its object based on the name of the input element. applicable to single choice and check boxes.
Function $ n (elementsname) {return document. getelementsbyname (elementsname );}
/*
Method Name getcheckboxvaluesary (cboxname, Boolean)
Return Value: returns an array of values in a status in the checkbox Group of the check box,
Parameter description,
Cboxname: check box name,
Boolean: true (selected) or false (not selected ),
Separator: The separator of the string. We recommend that you use non-sensitive characters.
Note: When copying data to other locations for use, use it together with the $ n (elementsname) method.
*/
Function getcheckboxvaluesary (cboxname, Boolean ){
VaR cboxobj = $ n (cboxname );
VaR cboxary = new array ();
For (VAR I = 0; I <cboxobj. length; I ++ ){
If (cboxobj [I]. Checked = Boolean ){
Cboxary. Push (cboxobj [I]. value );
}
}
Cboxobj = NULL;
Return cboxary;
}
/*
Check box for setcboxwholeselect (cboxname, Boolean) Method
Return Value: no return value.
Function: change the status of the check box whose name is cboxname to the value of Boolean.
Parameter description,
Cboxname: check box name,
Boolean: true (selected) or false (not selected ),
Note: When copying data to other locations for use, use the $ n (elementsname) method together. You can modify the method body as needed.
*/
Function setcboxwholestate (cboxname, Boolean ){
VaR cboxobj = $ n (cboxname );
For (VAR I = 0; I <cboxobj. length; I ++ ){
Cboxobj [I]. Checked = Boolean;
}
Cboxobj = NULL;
}
/*
Setcboxreverse (cboxname) Reverse Selection Check box
Return Value: no return value.
Function: select the status of the check box whose name is cboxname.
Parameter description,
Cboxname: check box name,
Note: When copying data to other locations for use, use the $ n (elementsname) method together. You can modify the method body as needed.
*/
Function setcboxreverse (cboxname ){
VaR cboxobj = $ n (cboxname );
For (VAR I = 0; I <cboxobj. length; I ++ ){
If (cboxobj [I]. Checked = false) {cboxobj [I]. Checked = true ;}
Else {cboxobj [I]. Checked = false ;}
} Cboxobj = NULL;
}
/* Check whether the phone number format is correct
Input parameter: string to be checked
Returned value: the format is correct. True is returned. Otherwise, false is returned.
*/
Function checktelformat (STR ){
VaR Reg =/^ (((/()? /D {2, 4 }(/))? [-(/S) *]) {0, 2 })? (/D {7, 8}) $ /;
If (Reg. Test (STR) // The phone number format is correct.
Return true;
Else // incorrect number format
Return false;
}
/* Use a regular expression to verify the email address
Input parameter: string to be verified
Returned value: True is returned if the format is correct. Otherwise, false is returned.
*/
Function checkmail (STR ){
VaR mailarray = Str. Split (",");
VaR patterns =/^ [a-zA-Z0-9 _-] + @ [a-zA-Z0-9 _-] + (/. [a-zA-Z0-9 _-] +) + $ /;
For (I = 0; I <mailarray. length; I ++ ){
If (patterns. Test (mailarray [I]) {return true;} // alert (STR + ", the mail address format is correct! ");
Else {alert ("'" + STR + "', the email address format is incorrect. Please check and enter it again !! "); Return false ;}
}
}
/* Check whether the input is in numeric format
Parameter: the character or string to be checked;
Return Value: Return true in numeric format; otherwise, return false;
*/
Function checknumber (STR ){
VaR letters = "1234567890 ";
VaR checkchar;
If (Str. Length <= 0) {// alert ("enter a number !! ")
Return false;
}
Else {
For (VAR I = 0; I <Str. length; I ++ ){
Checkchar = Str. charat (I );
If (letters. indexof (checkchar) =-1) {// alert ("enter a number !! ")
Return false;
}
}
Return true;
}
}