all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize
1 out of 3 rated this helpful - Rate this topic

pattern attribute | pattern property

Gets or sets a string containing a regular expression that the user's input must match.

This property is read/write.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4.10.7.3.9Internet Explorer 10

Syntax

HTML
<element pattern="ptr" ... >
JavaScript
object.pattern = ptr
ptr = object.pattern

Property values

Type: DOMString

String containing the regular expression used to match user input.

Standards information

Remarks

Several generic messages are displayed for a variety of validation errors. If you use a title attribute on an input element, it will both be shown as alt text for the field, as well as be appended to the generic error message.

The following example shows a ZIP code number format.


<p><label>*Zip: <input type="text" pattern= "[0-9](5|10)" placeholder="5 or 9 digit zip" title="5 or 9 digit zip" required /></label></p>


See also

HTMLInputElement

 

 

Send comments about this topic to Microsoft

Build date: 11/28/2012

Community Additions

ADD
© 2013 Microsoft. All rights reserved.