Solved

regex for street address format

Posted on 2009-05-18
5
1,356 Views
Last Modified: 2012-05-07
I need the regex expression for verifying a street address.
Our requirements are:
- start with a number
- contain at least one letter
0
Comment
Question by:nap0leon
  • 4
5 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 24411430
A regular expression to match that pattern would be:


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

Open in new window

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24411443
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
 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 24411468
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
 
LVL 41

Expert Comment

by:HonorGod
ID: 24411824
Thanks for the grade & points.

Good luck & have a great day.
0
 

Expert Comment

by:123print
ID: 26944606
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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now