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
LVL 18
nap0leonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
HonorGodConnect With a Mentor Commented:
e.g.,
<html>
<body>
 
Address: <input type='text' onchange='check(this)'>
 
<script type="text/javascript">
function check( obj ) {
  var re = new RegExp( '^[0-9]+ [A-Za-z]' )
  if ( re.test( obj.value ) ) {
    alert( 'ok' )
  } else {
    alert( 'invalid address' )
  }
}
</script>
 
</body>
</html>

Open in new window

0
 
HonorGodCommented:
A regular expression to match that pattern would be:


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

Open in new window

0
 
HonorGodCommented:
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
0
 
HonorGodCommented:
Thanks for the grade & points.

Good luck & have a great day.
0
 
123printCommented:
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.
0
All Courses

From novice to tech pro — start learning today.