Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

validate a postal code

by powerhouse (Friar)
on Jul 03, 2008 at 17:43 UTC ( [id://695404]=perlquestion: print w/replies, xml ) Need Help??

powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

It amazes me how many people don't know their own address! We have nearly 30,000 members in our database and are growing every day. I need to validate their address because when we go to ship them their product, we get errors. For instance, I got and Address in Estonia where they put the country as United States. The Zip code they put as 74117, my only check for United States is the zip code, but 74117 is in a valid format.

I have searched everywhere, including cpan for a module. My head is starting to hurt, I've spent hours on this and cannot find a good way to do it other than use LWP and just get a page off usps.com and then parse the HTML to find success or not... That could easily break by them just making a page change, so I need a different way to do it.

I would greatly appreciate any place you can point me to that has a solution.

We ship worldwide, except to Ghana and Nigeria... due to the amount of fraud we have received from there.

So I really need a solution that is not limited to the United States.

Thanks in advance for reading and for any pointers you have.

Update: We use USPS for our mailing, but we did just setup an account with UPS, and I found a module (Net::UPS) that will integrate our UPS account with our site to validate the addresses...<br
thx,
Richard

Replies are listed 'Best First'.
Re: validate a postal code
by Anonymous Monk on Jul 03, 2008 at 17:48 UTC

      That's US-only though. The OP said that wouldn't be enough.

      In general you're not going to be able to solve this problem. There are an awful lot of different address formats (eg compare the US, France and Japan), and there can even be different formats within a single country. Additionally, even if you could find a set of rules for each country, I know full well that the rules you'll get for the UK will be wrong, in that while they might specify what the post office *want* people to use, they will not be anything like what people *actually* use, and which *work*.

      And finally, don't even consider relying on a database lookup. There are plenty of addresses in the UK which the post office's database gets wrong, or which aren't even in the database. I live at one such address, and it's very annoying when programmers who really should know better are stupid enough to trust a database generated by a government body!

        I just need help with validating that it looks right, so if the formula's think it is wrong, I'll just post a confirmation page, that says your address does not look correct, so we need you to validate your input is correct. So please check the box that says "Yes I verify my address is deliverable by our local post office. I will pay re-shipment costs if it is returned." Then if they check the box, I'll just override that and let them get it through.

        Our members do not seem very intelligent though, for instance, one of the fields that one of our gateways asks for is: "nameoncard". Therefore my label read: "Name On Card". We had members put:
        Master Card (as their name)
        and: Visa Card (as their name)

        Those made me LAUGH OUT LOUD, seriously, but that is how un-intelligent that most of them are. I now changed that label to: Cardholder Name. That seemed to fix the problem, so far anyhow...
        I had to make our programming work for a little child, so I have my 10 year old check all my work. If he can understand it, then I figure our precious members can :).

        Still, we get hundreds of helpdesk posts per week for them not understanding how some of the things work. :o( Such is life.

        Anyhow, that is what I am wanting to do, is just 'Check' their entry, because I am having to manually fix some addresses because people are putting "United States" as their country field when they live in Canada, Estonia, Ireland, and one other was New Zealand.

        I will not force people to change it to match any database or fomula, just make them check their entry and then promise it is correct.

        Sorry for the long reply.

        thx,
        Richard
      Most Excellent! Thank you very much... that will save me a LOT of time!

      thx,
      Richard
Re: validate a postal code
by Anonymous Monk on Jul 03, 2008 at 18:08 UTC
    AddressDoctor provides a Web Service (for a fee) which has many many countries (each of which has its own website)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://695404]
Approved by moritz
Front-paged by DrHyde
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found