Validating postcodes

Posted by / 13-Mar-2020 12:53

Validating postcodes

Feel free to copy and paste it into your application. lc Test = ; CHRTRAN(tc Code, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", ; REPLICATE("A", 26)) lc Test = ; CHRTRAN(lc Test, "0123456789", ; REPLICATE("9", 10)) * Separate out the test string into outward and * inward portions lc Outward = ALLTRIM(LEFT(lc Test, LEN(tc Code)-4)) lc Inward = RIGHT(lc Test, 3) * The inward portion must be in the format 9AA IF lc Inward CHRTRAN(lc In Letters, "CIKMOV", "") RETURN . ENDIF * The outward portion must be in one of the * following formats: * A9, AA9, A99, AA99, A9A, AA9A IF NOT INLIST(lc Outward, ; "A9", "AA9", "A99", "AA99", "A9A", "AA9A") RETURN . It then become an easy matter to test the code against a list of valid patterns.

The inward code always consists of exactly one digit followed by exactly two letters.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.Unlike with US zip codes, you can't download a simple text file containing all known postcodes for use in validation routines.Essentially, every postcode consists of two elements, separated by a space.The outward part of the code comes first, then the space, then the inward part of the code.

validating postcodes-67validating postcodes-41validating postcodes-73

One thought on “validating postcodes”