Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
(^\d+\s+[\w ]+)[, ]+([a-zA-Z ]{3,})[, ]*({AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY})[, ]*([0-9-]{5,10}$)
/
gm

Description

Designed for a basic validation of a US address. Used in an Angular 6 app as an Address Validation. For extraction $1 is the numeric address, $2 is the street and apartment, $4 the state, and $5 the zip code.

Submitted by anonymous - 6 years ago