I used an ASP file on the Internet to dynamically generate the Form Verification javascript code, and expanded it myself. I forgot the author's name, but I remember that the code from the first to the ninth is the author's original. As for articles 9 to 15th, I added them myself. In addition, due to my limited level, I cannot see from article 9 to Article 15th that will take effect? In fact, there is no need to paste it here, because it will be used by anyone. I position it: when the function is not found during development, copy it here. Oh, because I neither have a burner nor a mobile hard disk. There is really no way to carry these codes with you, but fortunately, you can access the Internet everywhere in Beijing. So put this here. When using Ctrl + C, then Ctrl + V.
Copy codeThe Code is as follows: <%
'*************************************** *************************
'Function name: CheckForm_JS (frmName, errStr)
'Function: use ASP to dynamically write the javascript form verification function checkSubmit ()
'Usage: 1. <! -- Include File = URL + page where the function is located>;
'2. <form onsubmit = "javascript: return checkSubmit ()">;
'The Original Author has been forgotten. Author of secondary development: Guo. Q. M
'Last updated: 2004
'*************************************** *************************
'Help:
'---------------------------------------------------------------
'. Parameter description:
'Frmname: name of the form field
'Errstr: Verification List, such as: "num | 3 | model must be no less than 8 bits | 8, email | 5 | enter the correct email format", here
'Num indicates the form domain name, 3 indicates the verification parameter, and 8 indicates the number of digits not smaller than (optional)
'
'. List of verification parameters:
'0: required Text type
'1: Required ListMenu type
'2: The Text type must be a number.
'3: The Text type must be the specified number of digits.
'4: The Text type must be greater than the specified number of digits.
'5: The Text type of the Email must be used.
'6: The Text type must be a-z or 0-9 characters.
'7: confirm that the password and password must be of the same Text type
'8: Check whether the Text type starts with a number.
'9: The format must be 10-888888.
'10: Text type that cannot contain Chinese characters, spaces, and other illegal characters, that is, it can only contain "_" "-" "0-9" a-z "A-Z"
'11: The Text type must contain only numbers and "-".
'12: The Text type of the correct URL must be
'13: The Text type must be smaller than the specified number of digits.
'14: Text type that cannot contain HTML tags
'15: The Select type that is not disabled must be selected. Format: checked form items | 15 | prompt information | associated items"
'Note: If the cascade menu exists, put the verification process of the cascade menu to the final check !!!!
'------------------------------------------------------------------------
%>
<%
Sub CheckForm_JS (frmName, errStr)
Dim tmpArr
Dim I
Dim strShow 'output JS string
'Get the Error List and create an array
TmpArr = Split (errStr ,",")
'Write JS
For I = 0 to UBound (tmpArr)
If I <> 0 then
StrShow = strShow & "else" & findJS (frmName, tmpArr (I ))
Else
StrShow = strShow & findJS (frmName, tmpArr (I ))
End if
Next
'Output
StrShow = "<script language = javascript>" & vbCrlf &_
"<! -- "& VbCrlf &_
"// Power by Guoquanman 2004" & vbCrlf &_
"Function checkSubmit ()" & vbCrlf &_
"{" & VbCrlf &_
"Var emailReg =/^ [_ a-z0-9] + @ ([_ a-z0-9] + \.) + [a-z0-9] {2, 3} $/;" & vbCrlf &_
"Var pwdReg =/[a-z0-9] $/;" & vbCrlf &_
"Var uidBeginReg =/^ [0-9] + [_ a-z0-9]/;" & vbCrlf &_
"Var phoneReg =/\ d {2}-\ d {5}/;" & vbCrlf &_
"Var phoneDetailReg =/[^ 0-9 \-]/;" & vbCrlf &_
"Var uidReg =/[^ a-zA-Z0-9 _ \-]/;" & vbCrlf &_
"Var htmlReg =/<(. *)>. * <\/\ 1>/;" & vbCrlf &_
"Var re1 =/^ http: \/[A-Za-z] [A-Za-z0-9 \-] * [A-Za-z] * \. /; "& vbCrlf &_
"Var re2 =/^ http: \/[0-9] {} [A-Za-z] * [0-9] * \. /; "& vbCrlf &_
"Var re3 = // \. {2,}/;" & vbCrlf &_
"Var re4 =/\: {2,}/;" & vbCrlf &_
"Var re5 = // {3,}/;" & vbCrlf &_
"Var re6 =/\, +/;" & vbCrlf &_
"Var re7 = /\! +/; "& VbCrlf &_
"Var re8 = // @ +/;" & vbCrlf &_
"Var re9 = // # +/;" & vbCrlf &_
"Var re10 =/\ $ +/;" & vbCrlf &_
"Var re11 =/\ ^ +/;" & vbCrlf &_
"Var re12 =/\ * +/;" & vbCrlf &_
"Var re13 =/\ | +/;" & vbCrlf &_
"Var re14 =/\. [a-z0-9 _ & =? \/] * [A-Za-z0-9 \/\ ~] {2 ,}$/; "& vbCrlf &_
StrShow &_
"Else" & vbCrlf &_
"Return true;" & vbCrlf &_
"}" & VbCrlf &_
"// -->" & VbCrlf &_
"</Script>"
Response. Write strShow
End Sub
Function findJS (frmName, errStr)
Dim tmpArr
Dim I
'Parameter value
I = 0
'Get the Error List and create an array
TmpArr = Split (errStr, "| ")
'Output query Condition
Select Case tmpArr (I + 1)
Case "0" ': required Text type
FindJS = "if (document." & frmName & "." & tmpArr (I) & ". value) =") "& vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "1" 'mandatory ListMenu type
FindJS = "if (document." & frmName & "." & tmpArr (I) & ". value) =") "& vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "2" 'must be of the Text type of a number
FindJS = "if (isNaN (document." & frmName & "." & tmpArr (I) & ". value)" & vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "3" 'must be of the Text type of the specified number of digits
FindJS = "if (document." & frmName & "." & tmpArr (I) & ". value. length! = "& TmpArr (I + 3) &") "& vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "4" 'must be of the Text type greater than the specified number of digits
FindJS = "if (document. "& frmName &". "& tmpArr (I )&". value. length <"& tmpArr (I + 3) &") "& vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "5" 'must be the Text type of the Email
FindJS = "if ((! EmailReg. test (document. "& frmName &". "& tmpArr (I )&". value) & (document. "& frmName &". "& tmpArr (I )&". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "6" 'must be a-z or 0-9 Text
FindJS = "if ((! PwdReg. test (document. "& frmName &". "& tmpArr (I )&". value) & (document. "& frmName &". "& tmpArr (I )&". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "7" 'confirm that the password and password must be of the same Text type
FindJS = "if (document." & frmName & "." & tmpArr (I) & ". value )! = (Document. "& frmName &". "& tmpArr (I + 3) &". value) "& vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "8" 'confirm the Text type starting with a number
FindJS = "if (uidBeginReg. test (document. "& frmName &". "& tmpArr (I )&". value) & (document. "& frmName &". "& tmpArr (I )&". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "9" 'confirm the phone number in 10-101212 format
FindJS = "if ((! PhoneReg. test (document. "& frmName &". "& tmpArr (I )&". value) & (document. "& frmName &". "& tmpArr (I )&". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "10" 'confirm that only Text including English letters and "-", "_" are included. (Excluding Chinese characters and other special characters)
FindJS = "if (uidReg. test (document. "& frmName &". "& tmpArr (I )&". value) & (document. "& frmName &". "& tmpArr (I )&". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "11" 'confirm only numbers and Text types including "-" (commonly used telephone numbers and faxes)
FindJS = "if (phoneDetailReg. test (document. "& frmName &". "& tmpArr (I )&". value) & (document. "& frmName &". "& tmpArr (I )&". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "12" ': Check whether the website is valid!
FindJS = "if (((! Re1.test (document. "& frmName &". "& tmpArr (I) &". value ))&&(! Re2.test (document. "& frmName &". "& tmpArr (I) &". value ))"&_
"& (Document." & frmName & "." & tmpArr (I) & ". value! = '') | "&_
"(Re3.test (document. "& frmName &". "& tmpArr (I )&". value) | (re4.test (document. "& frmName &". "& tmpArr (I )&". value) | "&_
"(Re5.test (document. "& frmName &". "& tmpArr (I )&". value) | (re6.test (document. "& frmName &". "& tmpArr (I )&". value) | "&_
"(Re7.test (document. "& frmName &". "& tmpArr (I )&". value) | (re8.test (document. "& frmName &". "& tmpArr (I )&". value) | "&_
"(Re9.test (document. "& frmName &". "& tmpArr (I )&". value) | (re10.test (document. "& frmName &". "& tmpArr (I )&". value) | "&_
"(Re11.test (document. "& frmName &". "& tmpArr (I )&". value) | (re12.test (document. "& frmName &". "& tmpArr (I )&". value) | "&_
"(Re13.test (document." & frmName & "." & tmpArr (I) & ". value) | (! Re14.test (document. "& frmName &". "& tmpArr (I) &". value ))"&_
"& (Document." & frmName & "." & tmpArr (I) & ". value! = '')" & VbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "13" 'confirm that the Text type is not greater than the fixed number of digits
FindJS = "if (document. "& frmName &". "& tmpArr (I )&". value. length> "& tmpArr (I + 3) &") "& vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "14" 'confirm the Text type containing HTML tags
FindJS = "if (htmlReg. test (document." & frmName & "." & tmpArr (I) & ". value)" & vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". select ();" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus ();" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf
Exit Function
Case "15"
'================================================ ==============================
'The format of Select type that is not disabled must be selected: state | 15 | Select the province name! | SelCountry | city | select city information
'Note: the cascade menu item 1st is selectedIndex! If it is set to 0, 2nd items are disabled! No need to check the other two items
'When 1st items of the cascade menu are selectedIndex = 0, the selectedIndex of the first item cannot be 0, and the selectedIndex of the second item! When the value is 0, the selectedIndex value of the first item cannot be 0.
'This item is used to check the national/provincial/municipal cascade menus. if the country is not a Chinese country, the province and city can be left blank. If the country is a Chinese country, you must enter the province and the relative city!
FindJS = "if (document." & frmName & "." & tmpArr (I + 3) & ". selectedIndex = 0)" & vbCrlf &_
"{" & VbCrlf &_
"If (document." & frmName & "." & tmpArr (I) & ". selectedIndex = 0)" & vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus;" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf &_
"Else if (document." & frmName & "." & tmpArr (I) & ". selectedIndex! = 0) "& vbCrlf &_
"{" & VbCrlf &_
"If (document." & frmName & "." & tmpArr (I + 4) & ". selectedIndex = 0)" & vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 5) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I + 4) & ". focus;" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf &_
"}" & VbCrlf &_
"}" & VbCrlf
Exit Function
Case "16" 'select type is not disabled must Select format: Check Form Items | 16 | prompt information | Association items "NOTE: When the association item is the first item, confirm start!
FindJS = "if (document." & frmName & "." & tmpArr (I + 3) & ". selectedIndex! = 0) "& vbCrlf &_
"{" & VbCrlf &_
"If (document." & frmName & "." & tmpArr (I) & ". selectedIndex = 0)" & vbCrlf &_
"{" & VbCrlf &_
"Window. alert ('" & tmpArr (I + 2) & "');" & vbCrlf &_
"Document." & frmName & "." & tmpArr (I) & ". focus;" & vbCrlf &_
"Return false;" & vbCrlf &_
"}" & VbCrlf &_
"}" & VbCrlf
Exit Function
End Select
End Function
%>
**************************************** *******************************
Example: Copy codeThe Code is as follows: <% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
<! -- # Include file = "inc/check_formJS.asp" -->
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
'================================================ ==============================
'Form verification instance
'================================================ ==============================
'1. <! -- # Include file = "inc/check_formJS.asp" -->;
'2. Draw a form: name = "" onsubmit = "javascript: return checkSubmit ()" case sensitive;
3. Define Guo_Error // only one "," for example, adding "|" to the number of digits and Password Confirmation items to specify the parameter;
'4. Call CheckForm_js ("formname, Guo_Error)
'Www .china-u.com
'================================================ ==============================
Dim Guo_Error
Guo_Error = "text | 0 | the text item must be filled in !, "
Guo_Error = Guo_Error & "number | 0 | the number must be a number and must be a number !, "
Guo_Error = Guo_Error & "number | 2 | the number must be a number !, "
Guo_Error = Guo_Error & "digital | 3 | the number of digits must be 6 characters! | 6 ,"
Guo_Error = Guo_Error & "moredigital | 4 | the number of multiple items must be greater than 4! | 4 ,"
Guo_Error = Guo_Error & "email | 5 | Email address is required for Mail items !, "
Guo_Error = Guo_Error & "caractor | 6 | the character must be a string of 0-9A-Z !, "
Guo_Error = Guo_Error & "password2 | 7 | confirm that the password must be consistent with the password! | Password1 ,"
Guo_Error = Guo_Error & "listmenu | 1 | required! "
Guo_Error = Guo_Error & "uid | 8 | the user name cannot start with a number !, "
Call CheckForm_js ("form1", Guo_Error)
'================================================ ==============================
'Form verification process
'================================================ ==============================
'1. split the object to the array tempArr () through split (Guo_Error ();
'2. split the data to the array tempArr () through split (tempArr, "| ();
'3. Select Case split (tempArr (I + 1), "|") perform verification and output error message split (tempArr (I + 2 ));
'4. javascript is case sensitive. Therefore, the names of all form components must be consistent ~~
'================================================ ==============================
%>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Form Verification instance </title>
</Head>
<Body>
<Form name = "form1" method = "post" action = "check_form.asp" onsubmit = "javascript: return checkSubmit ()">
<P align = "center"> form to be verified </p>
**************************************** ***********************
Most of the above Code has passed the test, but is it easy to use? I can only say that the cascading drop-down menu is not very useful. Let's see which kind of man or WEB girl is improving it. Haha