HTML and CSS Reference
In-Depth Information
Again, JavaScript regular expressions are used primarily to verify data input on the
client side. When a user fills out a form and presses the submit button, the form is sent
to a server, and then often to a server script such as PHP, ASP.NET or a JavaServlet for
further processing. Although forms can be validated by a server program, it is more effi-
cient to take care of the validation before sending the script to the server. This is an
important function of JavaScript. The user fills out the form and JavaScript checks to see
if all the boxes have been filled out correctly, and if not, the user is told to reenter the
data before the form is submitted to the server. Checking the form on the client side
allows for instant feedback, and less traveling back and forth between the browser and
server. It might be that the server-side program does its own validation anyway, but if
JavaScript has already done the job, it will still save time and inconvenience for the user.
With the power provided by regular expressions, the ability to check for any type of
input, such as e-mail addresses, passwords, Social Security numbers, and birthdates is
greatly simplified. This chapter will teach you how regular expressions and their
metacharacters are used so that you will be able to read expressions even as complicated
as the one shown in Figure 17.1. There are a number of regular expression validators
and libraries on the Web. An excellent source is at .
Figure 17.1 A regular expression library. The user types “email” in the Search box.
See Figure 17.2 for results.
Search WWH ::

Custom Search