HTML input pattern property
Examples
Only contain three letters of the input field (no numbers or special characters):
<form action="demo_form.html">
Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">
<input type="submit">
</form>
Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">
<input type="submit">
</form>
try it"
Browser Support
Internet Explorer 10, Firefox, Opera and Chrome support pattern attribute.
Note: Safari or Internet Explorer 9 and earlier versions do not support the pattern attribute <input> tag.
Definition and Usage
attribute specifies the pattern used to validate <input> element of the value of regular expressions.
Note: pattern property applies to the following input types: text, search, url, tel , email and password.
Tip: Use the global title attribute to describe the mode to help users.
Tip: You can learn more about in our JavaScript tutorial regular expressions of knowledge.
Differences between HTML 4.01 and HTML5
pattern attribute is new in HTML5 attributes.
grammar
<input pattern="regexp">
Property Value
值 | 描述 |
---|---|
regexp | 规定用于验证 <input> 元素的值的正则表达式。 |
HTML <input> tag