After a period of programming, I feel that these JavaScript is long, so they are sorted out, and they have judge whether it is empty, judges the number, judging the amount, and the judgment time. Like those who can write into JS, it is simplified on the page.
Go off the space
Function Trim (STR) {
IF (str.charat (0) == "") {
Str = str.slice (1);
Str = Trim (STR);
}
Return Str;
}
Judging whether it is empty
Function isempty (potj, errmsg) {
Var obj = evAl (POBJ);
IF (obj == null || trim (obj.value) == "") {
IF (errmsg == NULL || errmsg == "")
Alert ("Enter is empty!");
Else
Alert (Errmsg);
Obj.focus ();
Return False;
}
Return True;
}
Judging whether it is a number
Function isnumber (Pobj, errmsg) {
Var obj = evAl (POBJ);
Strref = "1234567890";
IF (! iSempty (Pobj, Errmsg)) Return False;
For (i = 0; i Tempchar = obj.value.substring (i, i 1); IF (strref.indexof (tempchar, 0) == - 1) { IF (errmsg == NULL || errmsg == "") Alert ("Data does not meet the requirements, please check"); Else Alert (Errmsg); IF (Obj.Type == "Text") Obj.focus (); Return False; } } Return True; } // Judgment is a number, the number can be negative Function isnegative (Pobj, errmsg) { Var obj = evAl (POBJ); Strref = "1234567890-"; IF (! iSempty (Pobj, Errmsg)) Return False; For (i = 0; i Tempchar = obj.value.substring (i, i 1); IF (strref.indexof (tempchar, 0) == - 1) { IF (errmsg == NULL || errmsg == "") Alert ("Data does not meet the requirements, please check"); Else Alert (Errmsg); IF (Obj.Type == "Text") Obj.focus (); Return False; } else { IF (i> 0) { IF (Obj.Value.Substring (i, i 1) == "-") { IF (errmsg == NULL || errmsg == "") Alert ("Data does not meet the requirements, please check"); Else Alert (Errmsg); IF (Obj.Type == "Text") Obj.focus (); Return False; } } } } Return True; } Judgment is in the form of money Function ismoney (Pobj, errmsg) { Var obj = evAl (POBJ); Strref = "1234567890." IF (! iSempty (Pobj, Errmsg)) Return False; For (i = 0; i Tempchar = obj.value.substring (i, i 1); IF (strref.indexof (tempchar, 0) == - 1) { IF (errmsg == NULL || errmsg == "") Alert ("Data does not meet the requirements, please check"); Else Alert (Errmsg); IF (Obj.Type == "Text") Obj.focus (); Return False; } else { Templen = Obj.value.indexof ("."); IF (Templen! = - 1) { Strlen = obj.value.substring (Templen 1, Obj.Value.Length); IF (Strlen.length> 2) { IF (errmsg == NULL || errmsg == "") Alert ("Data does not meet the requirements, please check"); Else Alert (Errmsg); IF (Obj.Type == "Text") Obj.focus (); Return False; } } } } Return True; } Function isleApyear (Year) { IF ((Year% 4 == 0 && Year% 100! = 0) || (Year% 400 == 0))) { Return True; } Return False; } // Is judging whether it is correct? Function isdate (CheckText) { Var DateTime; VAR Year, Month, DAY; Var gone, gtwo; IF (Trim (CheckText.Value)! = "") { DateTime = Trim (CheckText.Value); IF (datetime.length == 10) { Year = datetime.substring (0, 4); IF (isnan (Year) == true) { Alert ("Please enter the date! Format is (YYYY-MM-DD) / N (2001-01-01)!"); CheckText.focus (); Return False; } Gone = datetime.substring (4, 5); Month = datetime.substring (5, 7); IF (isnan (Month) == True) { Alert ("Please enter the date! Format is (YYYY-MM-DD) / N (2001-01-01)!"); CheckText.focus (); Return False; } gtwo = datetime.substring (7, 8); Day = datetime.substring (8, 10); IF (isnan (day) == true) { Alert ("Please enter the date! Format is (YYYY-MM-DD) / N (2001-01-01)!"); CheckText.focus (); Return False; } IF ((gte == "-") && (gtwo == "))) IF (Month <1 || Month> 12) { Alert ("The month must be between 01 and 12!"); CheckText.focus (); Return False; } IF (DAY <1 || day> 31) { Alert ("Date must be between 01 and 31!"); CheckText.focus (); Return False; } else { IF (Month == 2) { IF (IsleApyear && Day> 29) { Alert ("February Date must be between 01 and 29!"); CheckText.focus (); Return False; } IF (! isleapyear (year) && day> 28) { Alert ("February Date must be between 01 and 28!"); CheckText.focus (); Return False; } } IF ((MONTH == 4 || Month == 6 || Month == 9 || Month == 11) && (day> 30)) { Alert ("in four, six, nine, November / N date must be between 01 and 30!"); CheckText.focus (); Return False; } } } else { Alert ("Please enter the date! Format is (YYYY-MM-DD) / N (2001-01-01)"); CheckText.focus (); Return False; } } else { Alert ("Please enter the date! Format is (YYYY-MM-DD) / N (2001-01-01)"); CheckText.focus (); Return False; } } else { Return True; } Return True; } script> Function Checked (theform) { if (! iSempty (TheForm.aa, 'Please enter the data')) Return False; } script> hEAD> Judgment whether input data The number of judgments Judgment amount form> body> html>