Jump to content

Recommended Posts

Hi, i'm after some information on validating address's from everywhere, probably postcode and telephone numbers are most important. Could someone show me a list of how each country formats theirs, even better for an example with php n regex.

 

I've done some googling, but it left me dangling with many pay services which look up for you, but i don't really need that level so...

 

Cheers in advance!!!

Link to comment
https://forums.phpfreaks.com/topic/73819-address-form-validation/
Share on other sites

Are you looking to validate that the address is properly formatted or that it is a valid address.

 

If the latter you will need to find APIs for each country you want to incorporate. If the former, then you could just look for existing functions for each country individually. Are you having users enter the entire address into a textarea? typically forrms require users to enter address data into discrete fields.

In essence it's really postcodes and phone numbers. I found this which is a good example for GB (http://www.ml-consult.co.uk/foxst-39.htm), but am searching for others. I've also found some references to the formats for other countries, whilst wiki has come up trumps for dialing codes and number formats. I'm just looking for the esay option, but quite happy to do it, prolly post it on 'PHP Freaks Forums > PHP and MySQL > FAQ/Code Snippet Repository' when I finish...

Can anyone tell me what characters are valid for the second set of characters in the 'outward code' section of a London postcode?

 

To illustrate, this is a typical UK postcode: SW1 1ZZ

Here is the postcode for 10 Downing Street: SW1A 2AA

As you can see there's an extra 'A' in the first section, i've also found 'B' (WC2B ***) in some case's. However I can't find a definitive list of valid characters, can you?

 

Here's what my regex look's like so far:

if(preg_match("/^[A-IK-PR-UWYZ]{1}[A-HK-Y]{0,1}[0-9]{1,2}[A-Z]{0,1} {1}[0-9]{1}[ABD-HJLNP-UW-Z]{2}$/",$e))
{
$res = "Valid";
}

As you can see i've used A-Z, but from some checklists i've got it validates invalid codes, such as 'GB7Z 1HQ'.

Also note that this currently only handles uppercase characters!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.