HTML and CSS Reference
In-Depth Information
FIGURE 2-10 The pattern attribute in action.
The value of the pattern attribute has to be a regular expression . Regular expressions can get
very complex; in fact, they're a topic worthy of a complete topic, but learning the basics of regular
expression use isn't too difficult. For more information on regular expressions, you can check out
http://www.regular-expressions.info .
Forms and input validation
Each HTML form should contain a submit button; when the submit button is pushed the browser
collects the content of the input fields and prepares to post it to the specified URL. Up until HTML5,
the browser was not responsible for validating the content of the form. Developers, though, could
hook up validation to the process using a bit of JavaScript code.
Validating a form entails checking that each input field in the form contains valid content.
Although the HTML5 standard doesn't mandate browsers to validate the content of a form, this is
indeed what happens by default with most browsers. HTML5 browsers give you a chance to disable
validation on the entire form, but not on individual fields. You can disable form validation by using
the novalidate attribute, as shown below in the file novalidate.htm :
<form novalidate>
<input type="text" placeholder="Your PIN"
title="2 letters + 6 digits"
pattern="[a-zA-Z]{2}\d{6}" />
<br />
<input type="submit" value="Enter" />
</form>
In this case, the content of the form is submitted to the server regardless of the data held by input
fields.
If the form contains multiple submit buttons, you can enable or disable validation on a per-button
basis so that validation occurs if users, say, click the first button but not the second. To disable
validation when the form is submitted via a particular submit button, you add the formnovalidate
attribute as follows:
<input type="submit" value="..." formnovalidate />
Search WWH ::




Custom Search