javascript| Form Validation | dynamic | function <%
' Please dump it for checkform_js.asp use
'*****************************************************************************
' Function name: Checkform_js (FRMNAME,ERRSTR)
' Function: Dynamically write JavaScript Form validation functions using ASP Checksubmit ()
' Use method: 1, <!--Include file=url+ the page >; of this function
' 2, <form >;
'*****************************************************************************
Help
'-----------------------------------------------------------------------------
' • Parameter description:
' Frmname: Name of form Field
' ERRSTR: Verify the list, such as: "num|3| model must be no less than 8 bits |8,email|5| Please enter the correct email format", here
' num indicates the form domain name, 3 is the validation parameter, and 8 is the number of digits not less than (optional)
'
' • Validate parameter list:
' 0: Required text type
' 1: Required type of Listmenu
' 2: Text type that must be a number
' 3: Text type that must be a specified number of digits
' 4: Text type that must be less than the specified number of digits
' 5: Must be the text type of email
' 6: The text type of the character that must be a-Z or 0-9
' 7: Confirm password and password must be equal to the text type
' 8: Character text type must be a-Z or 0-9 or a-Z
' 9: Text type that must be greater than the specified number of digits
'-----------------------------------------------------------------------------
%>
<%
Sub Checkform_js (FRMNAME,ERRSTR)
Dim Tmparr
Dim I
Dim strshow ' Output JS string
' Get the Error list, build the 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&_
"//powered by Dovia.net" &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&_
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, build the array
Tmparr=split (errstr, "|")
' Output query criteria
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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case "1" ' required type of Listmenu
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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case ' 2 ' must be a text type of 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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case "3" must be a text type of a 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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
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&_
"Return false;" &vbcrlf&_
"}" &vbcrlf
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
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&_
"Return false;" &vbcrlf&_
"}" &vbcrlf
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case "6" ' must be A-Z or 0-9-character text type
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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case "7" ' Confirm password and password must be equal to 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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case ' 8 ' must be a-Z or 0-9 or a-Z character text type
Findjs= "If" (!namreg.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
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
Case ' 9 ' 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&_
"Return false;" &vbcrlf&_
"}" &vbcrlf
' "Else" &vbcrlf&_
' Return true; ' &vbcrlf
Exit Function
End Select
End Function
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.