A collection of Common Regular Expressions
C# July 24th, 2006The following are a list of Regular expressions that I have either written or come across on other sites. This list will be expanded over time so check bak on this article.
| Usage | expression |
| Check email address | [code]([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})[/code] |
| Check URL | [code](ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?[/code] |
| UK Date dd/mm/yyyy | [code](((0[1-9]|[12][0-9]|3[01])([-./])(0[13578]|10|12)([-./])(\d{4}))|(([0][1-9]|[12][0-9]|30)([-./])(0[469]|11)([-./])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([-./])(02)([-./])(\d{4}))|((29)(\.|-|\/)(02)([-./])([02468][048]00))|((29)([-./])(02)([-./])([13579][26]00))|((29)([-./])(02)([-./])([0-9][0-9][0][48]))|((29)([-./])(02)([-./])([0-9][0-9][2468][048]))|((29)([-./])(02)([-./])([0-9][0-9][13579][26])))
[/code] |
An unbelievable source of expressions can be found at http://regexlib.com/DisplayPatterns.aspx
They even have a validator there.
February 2nd, 2007 at 4:04 pm
Can you post for US Date also
February 5th, 2007 at 10:05 am
US date validation
^([0]?[1-9]|[1][0-2])[./-]([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0-9]{4}|[0-9]{2})$
from http://regexlib.com/REDetails.aspx?regexp_id=932