HTML and CSS Reference
EXAMPLE 17.29 ( CONTINUED )
The regular expression reads: Look at the beginning of the line, ^, find an upper-
case letter, [A-Z] , followed by one or more lowercase letters, [a-z]+ , a single
whitespace, \s , and a digit at the end of the line, \d$ .
The user is prompted for input.
The regular expression test() method tests to see if there was a match and returns
true if so, and false if not. See Figures 17.30 and 17.31.
Figure 17.30 The string begins with a capital letter, followed by one or more lowercase
letters, a space, and ends with one digit (left); the input sequence matched, so this
message is displayed (right).
Figure 17.31 The regular expression does not match because the string ends in more than
one digit (left); the input sequence did not match, so this message is displayed (right).