Html 5 Form Pattern Attribute Tag

In the pattern attribute is used to validate input field through pattern. In the pattern is a regular expression. You can declare own requirement to input type field validation through regular expression. Pattern attributes will work input field types. Which input types are search, telephone, text, email and password.

Syntax:

<form>
  <input type="text" pattern="" />
</form>

Example Code



<!DOCTYPE HTML>
<form>
  <input type="text" name="postcode" id="postalcode" pattern="^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1}([ -])*\d{1}[A-Z]{1}\d{1}$" required />
  <input type="submit" value="Submit" />
</form>

Out Put :

In the above regular expression is a Canadian postal code validation. you enter postel code in the above form if postal code is worng message will display.





Content