Ensuring a Value Matches a Pattern

Description

The pattern attribute ensures that a value matches a regular expression.

Example

The following code shows the pattern attribute in use.


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="name"> Name: <input type="text" id="name"
        name="name" pattern="^.* .*$" />
      </label>
    </p><!-- w  ww. j  ava2s .  co  m-->
  </form>
</body>
</html>

Click to view the demo

Note

The pattern ensures that the user enters two names, separated by a space.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed