Thursday, September 13, 2012

Common Regular Expressions

Match letters, space, comma, ampersand, hyphen, forward slash, parentheses with length 1..12.
^[a-zA-Z0-9\s,&-/\(\)]{1,12}$
Match 2, 3 digit numbers with 0 to 2 decimal places.
[1-9]{2,3}(\.\d{1,2})?
Matches everything including control characters with length 5..255.
^[\w\d\s\W]{5,255}$
Postal code with min length 3, max length 10. Upper case alphabets, digits and spaces.
^[A-Z0-9\s]{3,10}$
Mobile number with length 10..15 with an optional plus '+' symbol in front.
^\+?[0-9]{10,15}$
Number with minimum 2 digit with first digit not zero and max 3 digit number, with optional decimal upto 2 place.
^[1-9]{1}\d{1,2}(\.\d{1,2})?$