HTML and CSS Reference
The for loop is used to check each character, one at a time, that was entered in the
The charAt() string method returns a character at a specified position in the
string. Each time through the loop, a new character is assigned to the variable, ch .
This is the test for alphabetic characters. Because each character is represented in-
ternally as an ASCII number, ( “A” is ASCII 65, “B” ASCII 66, etc.), any character
outside the range “A” to “Z” and “a” to “z” is not an alphabetic character.
If true is returned by the alpha() function, the form will be submitted.
The name of the form is alphachk . The onSubmit event is triggered when the user
clicks the Submit button on line 13.
The input type is a text field, called first . This is where the user will enter his or
her first name.
The input type is a text field, called last . This is where the user will enter his or
her last name.
The input type is a Submit button. When the user clicks this button, the onSubmit
event is triggered, and if the form was valid, it will be submitted to the server. (In
this example, it isn't going anywhere, because the action attribute of the form
wasn't specified.) See Figure 11.47.
Figure 11.47 The user enters a valid first name and an invalid last name.
Checking E-Mail Addresses. You are frequently asked to include your e-mail
address when filling out a form. There are some requirements for a valid e-mail address
such as TommyTucker@somewhere.com. One requirement is that there is an @ symbol
after the user name, and that there is at least one dot (.) in the address. The following
example is a preliminary check for the existence of both of those characters, but it is far
from a complete check. See Chapter 17 for a much more robust version of e-mail vali-
dation using regular expressions.