Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb
"Accelerated DOM Scripting with Ajax, APIs, and Libraries"
That being the case, then, you need JavaScript to do the
following:
1. Define the list of regular expressions and the fields to which they apply.
2. On page load, attach an onBlur handler to each field that has an applicable regexp.
3. The onBlur handler, which runs when the user??™s focus leaves a field, should check what
the user has entered in that field against the regexp.
4. If the regexp doesn??™t match what users enter, display an error message so they know
they??™ve entered something incorrectly.
Note that you??™re hooking up the JavaScript validation to the fields on page load, following
the DOM scripting principles of unobtrusiveness and progressive enhancement. If the user
doesn??™t have JavaScript, the hookup won??™t happen, but because you??™re already validating on
the server, the validation still happens and the page isn??™t broken. Equally, you??™re not mixing
lots of JavaScript code in with the HTML markup; the script is self-contained in a