input pattern Attribute - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:input

Description

The pattern attribute sets a regular expression that the <input> element's value is checked against.

The pattern attribute works with the following input types: text, date, search, url, tel, email, and password.

Attribute Values

Value Description
regexp Specifies a regular expression that the <input> element's value is checked against

An HTML form with an input field that can contain only three letters (no numbers or special characters):

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>A form with a URL field that must start with http:// or https:// followed by at least one character:</p>

<form action="/action_page.php">
  Homepage: <input type="url" name="website" pattern="https?://.+" title="Include http://">
  <input type="submit">
</form><!--  w w  w  .j av a2s .c o  m-->

</body>
</html>

Related Tutorials