I just read an interesting article concerning Regular Expressions and how they can be exploited as a denial of service attack. This is definitely a must read for anyone developing web apps which user RegEx.
Regular Expressions
24 MayBelow are some basic and more complexed standard expressions that I like to use in my interfaces. Feel free to comment with your versions and why you prefer your version over another standard expression.
Phone number formats:
Allows formated or unformated area code required US phone number
(((\(\d{3}\)(\s)?)|((\d{3})(\s|\-)?))?(\d{3}(\s|-)?\d{4}))
Single Initial:
[a-zA-Z]{1}
State Code Text:
[a-zA-Z]{2}
Zip Text one text box:
\d{5}((-|\s)(\d{4}))?
Zip Text two text box:
box1: [0-9]{5}
box2: [0-9]{4}
Date MM/DD/YYYY
Basic: [0-9]{1,2}/[0-9]{1,2}/[0-9]{4}
US Most: [0-9]{1,2}(/|\-|\.)[0-9]{1,2}(/|\-|\.)[0-9]{4}
US Tax ID
SSN: (\d{3}-\d{2}-\d{4}|[0-9]{9})
SSN or TIN: (\d{3}-\d{2}-\d{4}|[0-9]{9}) | (\d{2}-\d{7}|[0-9]{9})
Email Address
^(([\w-]+)@([\w-]+\.)+[A-Za-z]{2,3})$