Saturday, August 13, 2011

ASP.NET--Custom Validation Expression's

Some of the expression's that are used for validating the fields in the web form in ASP.NET

For Name:
^[a-zA-Z\s,.]{1-50}$

For Mobile Number:

^[7-9]{1}[0-9]{9}$

For Land-line Number:
^[0-9,\s,-]{10,13}$

For Car Registration Number:
^[a-zA-Z]{2}[0-9]{2}[a-zA-Z]{1,2}[0-9]{1,4}$

For E.mail:(Regular Expression)
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

For Website:
^((h|H?)(t|T?)(t|T?)(p|P?)(s|S?)\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\]+\.[a-zA-z]*$

Explanation:

^ and $                  -     For represents the Custom validation

a-z and A-Z            -     Letters from alphabets both upper and lower

0-9                        -     Numbers 0,1,2,3,4,5,6,7,8,9

\s (or) \S                -     Space between strings

{1,30} (or) {1,50}    -     Range or Count of the values. ex.  {min,max}

?                           -     For optional


No comments:

Post a Comment

Thanks for your valuable feedback.