International Zip Code Validation Javascript
Axel Foley wrote: I used some of the excellent resources from DITHERING.COM for help in my groveling newbie attempts to cough up working form validation. I cut and pasted bits of code to check USA ZIP codes and CANADIAN POSTAL codes, and merged them into one function that I called validCode. The tag has an onSubmit call to a general form-checker that works fine to make sure all fields are filled. But within the form is a ZIP/POSTAL CODE field, where the onBlur calls the function below: ' onBlur='validCode();'. The form-checking works fine, but when the 'onBlur' is engaged, it gives me an 'object expected' error where I'm defining the 'var zip'.
If any of you seasoned warriors could lend me a neuron or 2, I owe you a cappuchino or more. ============================= function validCode(zip) { var zip = removeSpaces(zip); You are calling onBlur='validCode();' but it needs to be: onBlur='validCode(this.value);' The function is expecting a parameter, tries to pass a parameter, and you aren't passing the parameter.
With our International Postal Address Verification Online API you. Real-Time Address Verification API. (CMS) is very easy - code examples in Javascript, PHP. The current validation rule for zipCode needs to support the following formats (5 digit and 9 digit): 5-6789. Also, the documentation for the zipCode rule. Form validation: postal / zip codes. JavaScript / Ajax / DHTML Forums on Bytes. Postal / Zip Code Validation. Best form validation tutorial?
Also, don't use onBlur to check it, use onChange instead. Then, it only gets checked when its actually been changed. Tabbing through the form will cause the onBlur to be needlessly fired.
-- Randy Chance Favors The Prepared Mind comp.lang.javascript FAQ.
There is none. Postal/zip codes around the world don't follow a common pattern. In some countries they are made up by numbers, in others they can be combinations of numbers an letters, some can contain spaces, others dots, the number of characters can vary from two to at least six. What you could do (theoretically) is create a seperate regex for every country in the world, not recommendable IMO. But you would still be missing on the validation part: Zip code 12345 may exist, but 12346 not, maybe 12344 doesn't exist either. How do you check for that with a regex?
@ddunn801, there's a (whomping big) differencee between validating the pattern and authenticating the postal code. Authenticating the codes is whole orders of magnitude more difficult since (at least in the U. Vocaloid 3 Singer Library. S.) postal codes are added and dropped regularly. In an ideal world, you would perform a quick-check to validate the pattern before submitting to a service (e.g., USPS) to validate the entire mailing address (services like this are paid, you'd hate to waste the value with bad data). Alas, the world is far from ideal. – Oct 26 '17 at 20:50.