NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Validating Against Patterns

You can check a user's entry matches a predefined pattern, such as a phone number, postal code, email address, and so on. To do so, you use a regular expression.

To validate against a data type

  1. Add a RegularExpressionValidator control to the page and set the following properties:
    Property Setting
    ControlToValidate The ID of the control you are validating.
    ErrorMessage, Text, ValidationDisplay Properties that specify the text and location of the error or errors that will display if the user skips the control. For details, see Controlling Validation Error Message Display.
  2. Set the pattern to compare to by setting the ValidationExpression property to a regular expression. Use the drop-down list in the Properties window to choose a pre-defined expression or to create a new one using a builder.
    Note   In client-side validation, you can use only regular expressions supported by JavaScript. For other details about client-side validation, see Client-Side Validation.
  3. Add a test in your Web Forms code to check for validity. For details, see Testing Validity Programmatically.

See Also

  1. Validation Controls | Introduction to Validating User Input in Web Forms |