HTML and CSS Reference
In-Depth Information
The second line of the function uses the test() method to determine whether the text
string stored in the zip parameter matches the pattern in the regular expression and
returns either a true or false value.
Starting with HTML5, regular expressions can be used directly on a Web form through
the pattern attribute. For example, the following HTML input element also tests for
valid postal codes:
<input name=”zip” type=”text” pattern = “^\d{5}(-\d{4})?$|^$” />
Notice that in this code you do not bracket the regular expression character string with
opening and closing / characters because you are not entering the expression as a regu-
lar expression literal. Browsers that support HTML5 apply this regular expression to the
data in the zip field and use it to validate that data.
Search WWH ::




Custom Search