ASP.Net/Validation by Function/Zip Code
Содержание
Regular Expression Validator Example: zip code
<source lang="csharp">
<%@ Page %> <html> <body>
Regular Expression Validator Example
<form runat="server"> Zipcode:<asp:TextBox id="_zipcode" runat=server/><asp:RegularExpressionValidator
ControlToValidate="_zipcode" Display="static" ErrorMessage="Zip code must be of the form 11111-1111" InitialValue="" width="100%" runat=server ValidationExpression="\d{5}(-\d{4})?">**
</asp:RegularExpressionValidator>
<input value="Enter" type=submit />
</form>
</body> </html>
</source>
Using a RegularExpressionValidator Control to Test a Zip Code (VB.net)
<source lang="csharp">
<%@ Page Language=VB Debug=true %> <script runat=server> Sub Answer_ServerValidation(source As object, E As ServerValidateEventArgs)
If E.Value = "VB" or E.Value = "VB.NET" or E.Value = "C#" _ or E.Value = "C#.NET" or E.Value = "A bunch of others." Then E.IsValid = True Else E.IsValid = False End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Using a RegularExpressionValidator Control to Test a Zip Code</TITLE>
</HEAD>
<form runat="server">
What languages can you use with ASP.NET?
<asp:textbox
id="txtAnswer" runat=server
/> <asp:customvalidator
id="custom9" controltovalidate="txtAnswer" OnServerValidate="Answer_ServerValidation" display="Dynamic" font-name="Verdana" font-bold="True" font-size="10pt" runat="server">
Incorrect answer please try again!
</asp:CustomValidator>
<asp:button
id="butOK" text="OK" type="Submit" runat="server"
/> </form> </BODY> </HTML>
</source>
Using a RegularExpressionValidator Control to Test a Zip Code with validationexpression (VB.net)
<source lang="csharp">
<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Using a RegularExpressionValidator Control to Test a Zip Code</TITLE>
</HEAD>
<form runat="server">
Please enter a 5-digit Zip Code:
<asp:textbox
id="txtZipCode" runat=server
/> <asp:regularexpressionvalidator
id="regZipCode" controltovalidate="txtZipCode" validationexpression="^\d{5}$" display="Dynamic" font-name="Arial" font-size="11" runat=server
>
Zip code must be a number in the form of 12345.
</asp:regularexpressionvalidator>
<asp:button
id="butOK" text="OK" type="Submit" runat="server"
/> </form> </BODY> </HTML>
</source>