I often look at others' code, I feel so refined. Sighing. Today, I posted a check function written by JavaScript on the Internet. I hope everyone likes it. . .
Function ValidateFunction (OBJ) {
IF (Obj == null) {
IF (Document.Forms [0])
Obj = Document.Forms [0];
Else
Return True;
}
Var formelements = obj.elements;
Var iCount;
For (iCount = 0; ICOUNT IF ((ForMelements [iCount]) || (ForMelements [iCount] .type == "textarea") && (formelements [iCount] .value! = null)) { / ** begin ** / Switch (formelements [iCount] .DATATYPE) { Case "int": { if (! Checkinteger (formelements [iCount], FormElements [iCount] .comment)) Return False; Break; } Case "Date": { IF (! checkdate (formelements [iCount], formelements [iCount] .coment)) Return False; Break; } Case "email": { if (! Checkemail (formelements [iCount], FormElements [iCount] .coment)) Return False; Break; } Case "float": { IF (! checkfloat (formelements [iCount], formelements [iCount] .comment) Return False; Break; } DEFAULT: { IF ((ForMelements [iCount] .maxlength! = null) && (! checkstring (formelements [iCount], formelements [iCount] .comment, formelements [iCount] .maxlength)))))) Return False; Break; } } / ** End ** / } IF (forMPITNUNT) && (! checknotnull (formelements [iCount], formelements [iCount])))) Return False; } Return True; } This function is a major calibration function, and other reference functions are given later, in all the types of checks, there must be Comment, and DataType properties, for example: If, DataType is a type of MaxLength if the CHAR type must have MaxLength, or the char type cannot be verified. These can be automatically generated by ASP, JSP scripting language.