1. firstly what is the regular expression validator?
  2. When we have to use a regular expression validator?
  3. What properties do we need to set for the regular expression validator?
  4. Practically solution.

In previously we already discuss the “required field validation ”, “Range validator & “Compared field validator” with a full description with practical solution checked it out

what is the regular expression validator?

The RegularExpressionValidator control enables you to compare the value of a form field against a regular expression. You can use a regular expression to represent string patterns such as email addresses, Social Security numbers, phone numbers, dates, currency amounts, and product codes.

Character Meaning for Character in Expression.

\w Any word character (Letter, Number, or Underscore).
\d Any digit.
\D Any character that is not Digit.
\s Any white space character like Tab or Space.
\S Any non-whitespace character.

Just like the other validation controls, the RegularExpressionValidator doesn’t validate a form field unless the form field contains a value. To make a form field required, you must associate a RequiredFieldValidator control with the form field. Character Meaning for Character in Expression

\w {10} 10 word character (Letter, Number or Underscore).
\w {5,10} Word character between 5 to 10.
\d {5,10) Any digits ranging from 5 to 10.
[A-D] Any 1 alphabet between A to D.
[A-Z]{5,15} Any alphabet between A to D but the no. of alphabets can be between 5 to 15.
\d{2}-\d{7,10} Ex. 99-999999 (2 digits then hyphen and after that digits between 7 to 10.

Practically solution.

Firstly you need to install visual studio and open it.

So, here we have to do a regular expression validator on the email id. means if email id is a perfect format its didn’t give any error. else it will show you an error.

firstly I have to take a textbox for email writing.

Secondly, I have to take a regular expression validator drag and drop it after the text box.

Now time to set the properties for regular expression validator for that-

  1. Firstly I have to write a error message like “enter valid email id” and set the color red.

2. Now time to set the Control to validate property – Select the text box5.

3. This is the most important property for any regular expression validator so you need to set it. Without it regular expression validator doesn’t work.

So, for email here I write this code ” \w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* ” .

I have to clarify it that for every formatting there is different code so you need to write that.

After that Regular expression validator will worked.

So, now run the program and write text into the text box. Here I write an email “xcoder913gmail.com” it is not the perfect formatting of an email id so it shows me the error message.

In this output I write the perfect format of error so it didn’t show any error message.

Leave a Reply

Your email address will not be published.