Help with regular expression for a physical address

Posted on 2009-04-28
Last Modified: 2012-05-06
I need a regular expression that will validate a physical address. (NOT EMAIL)
So like 222 Memory Lane #320

I want to avoid invalid special characters like ^$!*^= _ % ~ `
But keep these #,&, '   (That is single quuote is acceptable ex. 23 O'malley lane)
Question by:brgdotnet
    LVL 34

    Accepted Solution

    Not sure the flavor of regex you're using, but a PCRE (Perl Compatible Reg Ex) that checks for invalid characters would be something like:

    @^[a-z0-9 #,&.']*$@i

    eg in php:

    $pattern = '@^[a-z0-9 #,&.\']*$@i';
    if (preg_match($pattern,$address)) {
      print "Address is valid";
    LVL 2

    Author Comment

    I sure do appreciate your help. It did not work for me. I am using ASP.NET . I will repost this message in the section
    LVL 2

    Author Closing Comment

    Thank you for the help. Not quite what I wanted, but thanks

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
    As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    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…

    734 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

    19 Experts available now in Live!

    Get 1:1 Help Now