The pattern
attribute uses a regular expression to validate input values on form submission, supported by input types like text, email, and password. The title
attribute can describe the pattern for user guidance.
Example
An input field restricted to only three letters (excluding numbers and special characters):
<form> <label for=”country_code”>Country code:</label> <input type=”text” id=”country_code” name=”country_code” pattern=”[A-Za-z]{3}” title=”Three letter country code”> </form> |
The placeholder
attribute offers a brief hint about the expected input value, appearing in the field before the user types. It works with input types like text, email, and password.
Example
An input field featuring placeholder text:
<form> <label for=”phone”>Enter a phone number:</label> <input type=”tel” id=”phone” name=”phone” placeholder=”123-45-678″ pattern=”[0-9]{3}-[0-9]{2}-[0-9]{3}”> </form> |