HTML and CSS Reference
In-Depth Information
EXPLANATION
6
The for loop is used to check each character, one at a time, that was entered in the
text field.
7
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 .
8
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.
9
If true is returned by the alpha() function, the form will be submitted.
10
The name of the form is alphachk . The onSubmit event is triggered when the user
clicks the Submit button on line 13.
11
The input type is a text field, called first . This is where the user will enter his or
her first name.
12
The input type is a text field, called last . This is where the user will enter his or
her last name.
13
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.
 
Search WWH ::




Custom Search