Link to home
Start Free TrialLog in
Avatar of nap0leon
nap0leon

asked on

regex for street address format

I need the regex expression for verifying a street address.
Our requirements are:
- start with a number
- contain at least one letter
Avatar of HonorGod
HonorGod
Flag of United States of America image

A regular expression to match that pattern would be:


var re = new RegExp( '^[0-9]+ [A-Za-z]' )

Open in new window

The carot (i.e., '^' ) matches the "start of string",
the next thing (i.e., '[0-9]+') says one or more digits,
followed by a blank, and the last part (i.e., '[A-Za-z]') matches an upper or lowercase letter
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade & points.

Good luck & have a great day.
Avatar of 123print
123print

Um, no. That is not right. There are far more criteria involved in an address other than alpha numeric characters.

Look at:
/^([a-zA-Z0-9\.\-\ \/\#\\'])+$/

That should cover most of them. I am looking for a better one to cover PO Box disallows. But you have to consider special characters in addresses. Trust me on this one, I got pwnd on the phones after initial release of my code using a similar method to the accepted solution.