I have tried to use few of the properties of this control in my example.This will give a clear picture of the various benefits of this control.

Introduction

By using this RegularExpressionValidator control, you can check a user’s input based on a pattern that you define using a regular expression. This type of control allows you to check for predictable sequences of characters, such as those in email addresses, telephone numbers, postal codes, and so on.

Regular Expressions used in my example

Content

Regular Expression

Description

Password

\w+

Any sequence of one or more word characters.

Specific-Length Password

\w{4,10}

Password length must be at least 4 and max 10 characters.

Advanced Password

[a-zA-Z]\w{3,9}

The first char must be within the range of a-z or A-Z and its length must be at least 4 and max 10.

Limited-Length

\S{4,10}

It allows 4 to 10 characters, but it allows special characters.

Mobile Number

^([9]{1})([234789]{1})([0-9]{8})$

First digit must be 9. Second digit will be any 1 from (234789) and last 8 digits will be from 0-9.

Phone Number

\d{10}

Only 10 digits are allowed here.

Table 1: Regular Expressions used in my example

Properties used in my example

Property

Description

ControlToValidate

The ID of the form field being validated

ValidationExpression

ValidationExpression property is initialized with regular expression. It sets the pattern for comparison purpose.

EnableClientScript

Gets or sets a value indicating whether the RegularExpressionValidator control updates itself using client-side script.

Display

It is of 3 types:

None-RegularExpressionValidation control is not visible

Static- Space for error message is reserved irrespective of the non-occurrence of error.

Dynamic- Space for error message is not reserved in case of the non-occurrence of error.

Table 2: Properties of RegularExpressionValidator control used in my example