Thanks xblue and cgraz!
It's all working perfectly, except the postcode... 🙁
I don't understand lol!
if (!ereg('^[ \t]*([A-Z][A-Z]?)[ \t]*-?[ \t]*([1-9][A-Z]{1,2})[ \t]*-?[ \t]*([1-9][A-Z]{1,2})[ \t]*$', $postcode)) { // Postcode is incorrect... Do stuff...
This is what I got it from (on the internet 😛):
A more precise and valid parsing of British postcodes into its pieces, is:
(1) City/Town Code (1 letter min.):
Most codes have 2 letters, some have 1 letter, possible future codes may have more letters.
Optional (non standard) separator(s), such as space(s), used sometimes. May be stripped.
(2) City/Town Division (required):
1 non-null digit exactly
,
followed by optional letters (currently 1 max).
Examples: "A1", "A1X", "WF1", "WF1M"
Invalid: "A12", "WF12"
Optional separator (space or dash):
The separator is optional because of rule
-
above which limits the city code starting with a letter to having at most 1 embedded or final digit.
The standard separator is a space, but many hand-written postcodes would not have this space very visible, so this space must be optional and its position can be infered.
(3) Postcode suffix (3 characters min.):
1 or more digits (currently 1 max.)
optional letters (currently 2 max.)
Note that lowercase letters may be acceptable but should be avoided.
I assume that the letters I, S, and Z are avoided (to avoid confusion with the handwritten 1, 5 and 2 digits), like the digit 0 (which could be confused with the letter O).
But there may be exceptions (notably for the first letter of the code): "SI2" could be valid, and not "S12" for the City/Town +Division Code...
A regexp that matches these rules is:[/i]
$valid = eregi(
'^[ \t]*([A-Z][A-HJ-RT-Y]?)[ \t]*-?[ \t]*([1-9][A-HJ-RT-Y]{1,2})[ \t]*-?[ \t]*([1-9][A-Z]{1,2})[ \t]*$',
$postcode, $parse);
if ($valid) {
$citycode = strtoupper($parse[0]);
$divisioncode = strtoupper($parse[1]);
$suffixcode = strtoupper($parse[2]);
}
Sorry to ask so much, I appreciate all the help. 🙂