HTML and CSS Reference
In-Depth Information
EXPLANATION
1
The variable is assigned a regular expression containing a decimal character
\d
,
and followed by either one or zero literal periods,
\.?
. The question mark (zero or
one) controls the character preceding it, in this case a period. There is either one
period or no period at all in the string being matched.
2
The variable
textString
is assigned user input; in this example,
3.7
was entered.
3
The regular expression
test
method will return
true
because the string
3.7
matches
a decimal number, 3, followed by a period (or not one) and followed by another
decimal number, 7. See the examples in Figure 17.20.
Figure 17.20
The user entered
3.7
, or number, period, number (top); the user
entered
456
, or number, no period, number (middle); the user entered
5A6
, but
there must be at least two consecutive digits for a match (bottom).
EXAMPLE
17.19
<html>
<head><title></title></head>
<body>
<script type="text/javascript">
//
Greediness
Continues