What would be the best way to validate a zip code in jQuery, I'm not talking about if its a 5 character number, I'm talking about a VALID zip code, like it checks with some service to make sure its valid. By a valid zip code I mean a zip code in the USA that belongs to a City and State.
Asked
Active
Viewed 516 times
1
-
Define VALID zip code in your case – swapnesh Feb 15 '13 at 04:48
-
1Do you get all the zip codes with some api or may be if you store them in a json structure then you can validate them. – Jai Feb 15 '13 at 04:50
-
use `json` or `jsonp` as per this : `it checks with some service to make sure its valid.` – Jai Feb 15 '13 at 04:53
-
Use a service like those provided by [usps](https://www.usps.com/business/webtools-address-information.htm?) – Ja͢ck Feb 15 '13 at 05:24
1 Answers
0
I'm talking about a VALID zip code, like it checks with some service to make sure its valid.
var zipCode = getTheZipCodeFromSomeWhere();
jQuery.getJSON("http://example.com/some-service", { zipCode:zipCode }, function(data) {
updateZipCodeValidity(data.isZipValid);
});
You'll need to define getTheZipCodeFromSomeWhere()
, updateZipCodeValidity()
and http://example.com/some-service
as appropriate to your situation.

Armand
- 23,463
- 20
- 90
- 119