Skip to main content
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 Internet Explorer 10



<element pattern="ptr" ... >


object.pattern = ptr
ptr = object.pattern


Property values

Type: DOMString

String containing the regular expression used to match user input.

Standards information


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.

<!DOCTYPE html>

  <meta charset="utf-8" />
      Zip: <input type="text" 
                  placeholder="5 or 9 digit zip" 
                  title="5 or 9 digit zip" 
                  required />
    <input type="submit" />

See also