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.


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

Example Code

  <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" />

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.