Skip to content Skip to sidebar Skip to footer

Simple Regex For Street Address

I know there are a dozen questions at least on this. I am trying to have a simple validation of input for street address using Regex whereby I check for at least two spaces in the

Solution 1:

\w+(\s\w+){2,}

Description:

  • \w+ => Alphanumeric, one or more repititions
  • \s => Whitespace
  • (\s\w+) => A numbered capture group [\s\w+]
  • {2,} => at least 2 repititions

Solution 2:

You've got some viable suggestion here. I would however like to offer you a regex that I think does what you asked for:

\d+\s+\w+\s+\w+

or, if it's a warning only, you could even add testing of "types" you indicated, like:

\d+\s+\w+\s+(?:st(?:\.|reet)?|ave(?:\.|nue)?|lane|dr(?:\.|ive)?)

allowing for abbreviated version with or without full stop. (Add road, court, etc. at will)

Check it out at regex101.

Hope this helps,

Regards

EDIT: Remember to add flag for case insensitive. ;)

Solution 3:

I could not get the other guys to work for some reason but this one validates all street addresses I have ever come up with...

var value = '12136 Test This Road';
var streetAddRegEx = RegExp('/\d{1,}(\s{1}\w{1,})(\s{1}?\w{1,})+)/g');
streetAddRegEx.test(value);

Basically I made it so it was any set of words more then one proceeding a set of numbers...

Solution 4:

Improved version based on ClasG's answer.

/\d+(\s+\w+){1,}\s+(?:st(?:\.|reet)?|dr(?:\.|ive)?|pl(?:\.|ace)?|ave(?:\.|nue)?|rd|road|lane|drive|way|court|plaza|square|run|parkway|point|pike|square|driveway|trace|park|terrace|blvd)/

Solution 5:

^(?!\s*$)^((?!([p|P][-. ]?[o|O].?[-]?|post office )[b|B]([ox|OX]))(?!(\`|\~|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\+|\=|\[|\{|\]|\}|\||\\|\'|\<|\,|\.|\>|\?|\"|\;|\:)).)*$

Post a Comment for "Simple Regex For Street Address"