HTML Form How to - Apply pattern to HTML 5 Input attributes








Question

We would like to know how to apply pattern to HTML 5 Input attributes.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--from   w w  w  . j  ava 2s  . c o m-->
<body>
  <form>
    <input name="zipcode" type="text" pattern="\d{4}\s?[A-Za-z]{2}"
      length="7" required="true" /> <input type="submit" />
  </form>
</body>
</html>

The code above is rendered as follows: