Archive | Regular Expressions RSS feed for this section

Security and Regular Expressions — A Good article by Bryan Sullivan, MSDN magazine (May 2010)

1 Jun

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.

http://msdn.microsoft.com/en-us/magazine/ff646973.aspx

Regular Expressions

24 May

Below 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})$

Follow

Get every new post delivered to your Inbox.