HTML and CSS Reference
In-Depth Information
It is also possible to set type to search , which may eventually have an associated pick
list. Currently, some browsers provide some controls for clearing a search field:
Validating Data Entry
We have already seen a number of HTML5 changes that allow us to restrict the type of data
entered into a form. It is also possible to force the user to enter data, without resorting to
JavaScript, in an HTML5-compliant browser by setting the required attribute for a form
control:
<input type="text" name="firstname" id="firstname" required>
A browser may then set an error style on the field and present a message if there is a
problem:
The pattern attribute also can be employed to force the entered data to conform to a
supplied regular expression:
<label for="phonenum" class="required"> Phone Number: </label>
<input type="text" name="phonenum" id="phonenum" required
pattern="^\(\d{3}\) \d{3}-\d{4}$">
If a title is specified when patterns are applied, the browser may display this advisory
information:
<label for="phonenum" class="required"> Phone Number: </label>
<input type="text" name="phonenum" id="phonenum" required
pattern="^\(\d{3}\) \d{3}-\d{4}$"
title="Phone number of form (xxx) xxx-xxxx required">
However, in some cases, you can not only apply a pattern but also employ the
appropriate semantic type value like email , though it isn't clear if these elements will apply
their own implied validation pattern matches simply by setting them as required :
Search WWH ::




Custom Search