The pattern attribute is a form validation attribute that is used to validate the value of an input field against a regular expression. Regular expressions are used for advanced pattern matching of text strings. The pattern attribute’s regular expression is written using the same syntax available to a JavaScript RegExp pattern, but with the global, ignoreCase, and multiline options disabled.

Syntax:

<input type="text" pattern="^[A-Za-z0-9]+$" />

Elements:

NOTE: the validation triggered by the pattern attribute can be bypassed through the use of the novalidate or formnovalidate attributes.

Information on writing regular expressions can be found at: 

http://brenkoweb.com/tutorials/javascript/js-regular-expressions

Example

The example with patter attribute:

 

›› go to examples ››