Commonly used reguler expressions

In most of the projects you may be used various reguler expressions frequently. Here is the list of some commonly used reguler expressions for validating your forms.

E-mail:


^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$


Example:yourname@provider.com

URL:


^(htf)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$


Example: http://www.dotnetspider.com

US Social Security Number:


^\d{3}-\d{2}-\d{4}$


Example: 111-11-1111

Phone number(Validates US Phone number):


^[01]?[- .]?(\([2-9]\d{2}\)[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$


Examples:
(234) 656-0123
234-444-0123
325 444 0123
1-325-444-0123

Zip Code(Validates US Zip code):


^(\d{5}-\d{4}\d{5}\d{9})$^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$


Example:
23456

Currency(Non Negative):


^\d+(\.\d\d)?$


Example:
23.00

Currency(+ve or -ve):


^(-)?\d+(\.\d\d)?$


Example:
23.00
-24.00

Non Negative Integer:


^\d+$


Examples:
123
456

Hope this helps you.

Reference: http://msdn.microsoft.com/en-us/library/ms972966.aspx


Comments

Author: Abhay Kumar Raut05 Nov 2009 Member Level: Gold   Points : 1

Hi prajeesh,
can u add one example for each?

It will be better.
It is looking odd also.

Author: Prajeesh05 Nov 2009 Member Level: Gold   Points : 0

Hi Abi,

I added examples for each, also formatted a bit.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: