Populer Topics

Regular Expression Validator

The Regular expression validator control is used to ensure that an input value match a specified pattern. The regular expression validator control enable us to compare the value of a form fields against the regular expression.

We can use a regular such as expression to represent string pattern such as email address, social security number, phone number, date, currency amount and product code both server and client side validation are perform unless the browser doesn’t support client side validation so enable client script is set false.

The validation will not fail if the input control is empty, use required field validation control to make required field.

This control provides following properties.

Property Description

ControlToValidate

This Property is used to set the control which we want as required field. General textbox, dropdownlist and listbox are set as control to validate.
ValidationExpression Specifies the expression used to validate input control. The expression validation is different from the client they on the server. JavaScript is use on the language we have specified used.
Display The Display behavior for the validation control its value are None : The control is none display and the error is display only in validation summary control. Static: Control display an error message the validation is ready. Display: The Control display error message but space is not reserved on the page for the message.
ContorlToValidate This property is used to set the control which we want to validate.
ErrorMessage The Text to display the validation summery control when validation fails. This takes text will also be display into validation control if the text property is not set.
Text This is also one property to set an error message but used to error message only on validation control. If error message and text both property set the error message will be display on validation summery. Text property display on validation control.
ValidationGroup This is used to set the validation group. If we have different group of validation under same page than we can use this property.

There are different regular expression given below.

Character Description
\W Any word character (Latter, Number and underscore)
\d Any digit
\D Any character not allowed digit
\s Any white space character like tab or space.
\S Any none white space character.

There are some expressions with example as following.

Expression Description
\W{10} Ten characters are allowed.
\w{5, 10} Allow 5 to 10 characters.
\d{5, 10} Any running digit from 5 to 10.
[A-D] Any one alphabet between A to D.
[A-D]{5} Any five alphabets between A to D.