HTML and CSS Reference
In-Depth Information
EXAMPLE 17.29 ( CONTINUED )
else{
alert("No Match!");
}
</script>
</body>
</html>
EXPLANATION
1
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$ .
2
The user is prompted for input.
3
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).
Search WWH ::




Custom Search