An example of an inaccurate ZIP Code™: that specify the exact delivery location.It also is referring to Boston, MA rather than Charlestown, MA.What you could do (theoretically) is create a seperate regex for every country in the world, not recommendable IMO. Unless you have a large enough budget to track this, you are almost certainly better off giving the responsibility of validating addresses to google or yahoo.But you would still be missing on the validation part: Zip code Google also has a web service with per-country address formatting information, including postal codes, here - (I found that link via ) Edit Here a copy of postal Code regex : "GB", "GIR[ ]? Both companies provide address lookup facuilities through a programmable API.This is so that if the user enters invalid characters, we still parse/format the space correctly.Naturally, we also use a display picture clause to render with the space: Because we know that the input data is in upper case, it makes our validation logic cleaner, as it needs only be concerned with the upper case variations.The challenge is to get an accurate and user-friendly data capture experience for a postal code. However, this picture allows many illegal postal codes.For example, the meta character “A” in a picture clause allows any Unicode letter value – whereas a postal code letter is far more restricted: When the user enters an invalid postal code, be as specific as possible in telling them what to fix.
While the subject domain is fairly specific, the techniques used are applicable to other field validations.
Since only about 12% of the possible 7.2 million postal code variations are currently allocated, it is still pretty easy to enter a non-existent postal code.
Because this validation script is as specific as possible, it does mean that the script may need to be updated as the postal code rules evolve (The Canadian postal code rules were modified after Nunavut was added in 1999).
In a couple of cases (M and H) we can also assign the value for the city (Toronto and Montréal).
While we now have a better-than-average postal code validation, it does not ensure100% correctness.