16 February 2014

Regular Expression Validator -Validation Controls

   It is derived from Regular Expression Validator class.The regular Expression Validator control is used to determine whether the value of an input control matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses, telephone numbers, postal codes, and so on.

Use the validation Expression  property to specify the regular expression used to validate an input control. The regular expression validation syntax is slightly different on the client than on the server. On the client, JScript regular expression syntax is used. On the server, regex syntax is used. Because JScript regular expression syntax is a subset of Regex syntax,

Syntax

For accepting only 5 digit Zip Code

<asp:RegularExpressionValidator id="RegularExpressionValidator1"
                     ControlToValidate="TextBox1"
                     ValidationExpression="\d{5}"
                     Display="Static"
                     EnableClientScript="false"
                     ErrorMessage="ZIP Code must be 5 numeric digits"
                     runat="server"/>

No comments:

Post a Comment