So I want to write a validation that checks a zip code in a html input text. I want to check if a zip code is from a particular state then it will give an error, telling that it is from that state and it’s not allowed.. otherwise if the user enters some other zipcode, this should be fine. How do I do that?
Share
The way ZIP codes are assigned, each states’ ZIP codes fall within a particular range. If you ignore the fact that not all ZIP codes in those ranges are currently in use, you could construct a regex that would match only ZIP codes for particular states. (see http://en.wikipedia.org/wiki/ZIP_code for the ranges).
I think a function with some
ifstatements would be simpler though: