I used an ASP dynamically generated Form verification javascript code on the Internet and expanded it myself. I forgot the author's name, but I remember clearly that the codes from Article 1 to Article 9 are all original works of the author. As for Articles Nine to Fifteen, I added it myself. Moreover, due to my limited level, from Article 9 to Article 15, may not take effect all of them? Haha, there is actually no need to post it here, because everyone can use this little trick. I positioned its function as: when you can't find the function during development, you can just copy it here. Haha, because I don’t have a burner or a mobile hard drive. 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, use Ctrl+C, and then Ctrl+V.
<% '************************************************************************
'Function name: CheckForm_JS(frmName,errStr)
'Function: Use ASP method to dynamically write javascript form verification function checkSubmit()
'Usage method: 1. <!--IncludeFile=URL+page where this function is located>;
'2. <formosubmit="javascript:returncheckSubmit()">;
'The original author has been forgotten, the second development author: Guo.QM
'Last update: 2004
'************************************************************************
'help:
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'·Particle description:
'frmName: The name of the form field
'errStr: Verify the list, such as: "num|3|model must not be less than 8 digits|8, email|5|Please enter the correct email format", here
'num represents the form field name, 3 represents the verification parameter, 8 represents the number of digits not less than (optional)
'
'·Verification parameter list:
'0: Required Text Type
'1: Required ListMenu type
'2: Must be a text type of number
'3: Must be the Text type of the specified number of digits
'4: The Text type must be greater than the specified number of digits
'5: Must be the Text type of Email
'6: Must be az or characters of 0-9
'7: Confirm the password and password must be equal to the Text type
'8: Confirm that it is not a Text type that starts with a number
'9: Must contain Text type in format 10-888888
'10: Text types that cannot contain Chinese, spaces and other illegal characters, that is, they can only contain "_""-""-""0-9""az"AZ"
'11: Must include only the number and "-"
'12: Must be the correct URL's Text type
'13: Must be less than the specified number of digits Text type
'14: Text types that must not contain HTML tags
'15: Confirm that the Select type is not disabled must select the format: checked form item|15|prompt information|association item"
'Note: If there is a cascading menu, please put the verification process of the cascading menu to the last inspection! ! ! !
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%>
<%
SubCheckForm_JS(frmName,errStr)
DimtmpArr
Dimi
DimstrShow' output string of JS
'Get the error list, create an array
tmpArr=Split(errStr,",")
'Writing JS
fori=0toUBound(tmpArr)
ifi<>0then
strShow=strShow&"else"&findJS(frmName,tmpArr(i))
else
strShow=strShow&findJS(frmName,tmpArr(i))
endif
next
'Output
strShow="<scriptlanguage=javascript>"&vbCrlf&_
"<!--"&vbCrlf&_
"//PowerbyGuoquanman2004"&vbCrlf&_
"functioncheckSubmit()"&vbCrlf&_
"{"&vbCrlf&_
"varemailReg=/^[_a-z0-9]+@([_a-z0-9]+/.)+[a-z0-9]{2,3}$/;"&vbCrlf&_
"varpwdReg=/[a-z0-9]$/;"&vbCrlf&_
"varuidBeginReg=/^[0-9]+[_a-z0-9]/;"&vbCrlf&_
"varphoneReg=//d{2}-/d{5}/;"&vbCrlf&_
"varphoneDetailReg=/[^0-9/-]/;"&vbCrlf&_
"varuidReg=/[^a-zA-Z0-9_/-]/;"&vbCrlf&_
"varhtmlReg=/<(.*)>.*<///1>/;"&vbCrlf&_
"varre1=/^http:////[A-Za-z][A-Za-z0-9/-]*[A-Za-z]*/./;"&vbCrlf&_
"varre2=/^http:////[0-9]{1,5}[A-Za-z]*[0-9]*/./;"&vbCrlf&_
"varre3=//.{2,}/;"&vbCrlf&_
"varre4=//:{2,}/;"&vbCrlf&_
"varre5=///{3,}/;"&vbCrlf&_
"varre6=//,+/;"&vbCrlf&_
"varre7=//!+/;"&vbCrlf&_
"varre8=//@+/;"&vbCrlf&_
"varre9=//#+/;"&vbCrlf&_
"varre10=//$+/;"&vbCrlf&_
"varre11=//^+/;"&vbCrlf&_
"varre12=//*+/;"&vbCrlf&_
"varre13=//|+/;"&vbCrlf&_
"varre14=//.[a-z0-9_&=?//]*[A-Za-z0-9///~]{2,}$/;"&vbCrlf&_
strShow&_
"else"&vbCrlf&_
"returntrue;"&vbCrlf&_
"}"&vbCrlf&_
"//-->"&vbCrlf&_
"</script>"
Response.WritesstrShow
EndSub
FunctionfindJS(frmName,errStr)
DimtmpArr
Dimi
'Parameter value
i=0
'Get the error list, create an array
tmpArr=Split(errStr,"|")
'Output query conditions
SelectCasetmpArr(i+1)
Required Text Type for Case"0"'
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Required ListMenu Type for Case "1"
findJS="if((document."&frmName&"."&tmpArr(i)&".value)=="""")"&vbCrlf&_
"{"&vbCrlf&_
"window.alert('"&tmpArr(i+2)&"');"&vbCrlf&_
"document."&frmName&"."&tmpArr(i)&".focus();"&vbCrlf&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "2"' must be the Text type of the 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "3"' must be 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "4"' must be greater than 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "5"' must be the Text type of 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "6"' must be of az or a Text type of characters of 0-9
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case"7"' confirms that the password and password must be equal to the 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "8"' confirms 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "9"' confirms the phone number in format 10-101212
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case"10"' confirms that only text including English letters and "-","_". (That is, it does not include Chinese 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case"11"' confirms that only contains numbers and "-" (commonly used in phone 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "12"' confirms whether it is a valid URL!
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "13"' confirms 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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "14"' confirms the Text type containing HTML tag
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case"15"
'================================================================================
'Confirm that the Select type is not disabled must select the format: state|15|Please select the province name! |selCountry|city|Please select city information
'Note: When selectedIndex!=0, item 2 and item 3 are disabled! No need to check the other two items
'When the first item selectedIndex==0 of the cascading menu, the selectedIndex of the second item cannot be 0, and when the second item selectedIndex!=0 of the second item, the selectedIndex of the third item cannot be 0 either.
'This item is used to check the three cascade menus of the country/province/city. When the country is not China, the province and city may not be filled in. When it is China, the province and the relative city must be filled in!
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf&_
"elseif(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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf&_
"}"&vbCrlf&_
"}"&vbCrlf
ExitFunction
Case "16"' confirms that the Select type is not disabled must select the format: checked form item|16|Prompt information|Association item" Note: When the associated item is the first item, confirmation starts!
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&_
"returnfalse;"&vbCrlf&_
"}"&vbCrlf&_
"}"&vbCrlf
ExitFunction
EndSelect
EndFunction
%>