is a PHP class that can validate postcode formats, extract parts of postcodes, and determine the post towns corresponding to postcodes.
Download the two files below and upload them to your web server.
Note that this function only validates the format of a postcode and does not validate that the postcode exists; this would require access to the Royal Mail database.
A postcode consists of various parts, from the area (the initial letters, corresponding to 121 divisions of the UK) to the unit (the entire postcode).
^(([g G][i I][r R] 0[a A])|((([a-pr-uwyz A-PR-UWYZ][a-hk-y A-HK-Y]? |(([a-pr-uwyz A-PR-UWYZ][0-9][a-hjkstuw A-HJKSTUW]|([a-pr-uwyz A-PR-UWYZ][a-hk-y A-HK-Y][0-9[abehmnprv-y ABEHMNPRV-Y])))&[0-9][abd-hjlnp-uw-z ABD-HJLNP-UW-Z]))$ Can anyone please help me with the other lines I would need to type to get this validation to work.
I checked the above code with the source and typed it into my programme (see below) when I tried to run the programme it came up with 54 errors. namespace Moondog_odering_system I found this on another thread on this site.
They are widely used to link individuals to various types of geographical, demographic and marketing data, and it's especially important that they are recorded and processed accurately.
Thus, if your application processes UK postcodes, you'll need an effective way of validating them. If you don't have access to the PAF, you can at least check that the postcodes in your application follow these rules.
The database is only required for the get Post Town function.