Applications Windows
Réduire la table des matières
Développer la table des matières
EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

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.9

 

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.


<!DOCTYPE html>

<html>
<head>
  <meta charset="utf-8" />
  <title>pattern</title>
</head>
<body>
  <form>
    <label>
      Zip: <input type="text" 
                  pattern="(^\d{5}$)|(^\d{5}-\d{4}$)" 
                  placeholder="5 or 9 digit zip" 
                  title="5 or 9 digit zip" 
                  required />
    </label>
    <input type="submit" />
  </form>
</body>
</html>

See also

HTMLInputElement

 

 

Afficher:
© 2016 Microsoft