Validating Zip Codes

Those wacky users can type almost anything into a form, so you’ll want to make sure that if they entered anything into the Zip code field (Figure 7.11) that it contains only numbers. Script 7.14 shows you how.

Figure 7.11. You can make sure that the user either enters a Zip code or makes a selection from the scrolling list.

To make sure Zip codes are valid:

1.
if (allGood && !isNum(thisTag.value)) {
  classBack = "invalid ";
}
  classBack += thisClass;
This goes into the isNum block of the switch/case conditional. If the entry is non-numeric, isNum() returns false.
2.
if (allGood && !isZip(thisTag.value)) { classBack = "invalid ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.