Regular Expressions for Common Tasks

Another installment in the I’ve got just the thing here….somewhere series.

U.S. Postal code

/^$|^(\d{5}(( |-)\d{4})?)/

Telephone

/^(0|1)?[\s|\.|\-]?[\(]?(\d{3})[\)]?[\s|\.|\-]?(\d{3})[\s|\.|\-]?(\d{4})[\s|\.|\-]?(extension|ext|ex|x)?[\s]?(\d{0,5})?$/

Fax

/^$|^(0|1)?[\s|\.|\-]?[\(]?(\d{3})[\)]?[\s|\.|\-]?(\d{3})[\s|\.|\-]?(\d{4})$/

Email

[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}


Add Your Comment