Solved

regex for street address format

Posted on 2009-05-18
5
1,363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

627 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