?
Solved

UK Postcode

Posted on 2006-06-06
1
Medium Priority
?
690 Views
Last Modified: 2012-08-14
I have a list of UK Postcode that I need to check for the correct format.  

Users address are entered like: $address = "street, town, city, county, postcode";

I split these up into parts like so: $part = explode(',',$Address); which gives me:

$part[0] = 'street';
$part[1] = 'town';
$part[2] = 'city';
$part[3] = 'county';
$part[4] = 'postcode';

But some users enter their phone number instead of the postcode which gives me a pain in the head...

So i'd like to check the last part in the string so I can either put the value in a $telephone = '0123456789'; or $part[4] = 'AB10 1LB';

So how would i check the format of a Postcode? example: AB10 1LB

thank you
0
Comment
Question by:ellandrd
1 Comment
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 16841781
Hi,

if(preg_match('/^[a-z]+\d+\s+\d+[a-z]+$/i', $part[4])) {
  //postcode
} else {
  //tel
}

-r-
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 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