Wednesday, October 28, 2009

Fun With Regular Expressions

I needed a regular expression to handle phone numbers in a variety of formats. Came up with the following:

([(]?\d{3}[)]?(- .)?\d{3}(- .)?\d{4})

It works with just about any U.S. number you can throw at it.

(800) 555-1212
800.555.1212
800-555-1212
8005551212

No comments: