Skip to content
techsnow

HTML Forms

Form Validation

HTML can check user input before the form is sent, with no JavaScript at all. The browser shows a message and stops the submission if something is wrong.

AttributeRule
requiredMust not be empty.
type="email" / "url"Must look like an email / web address.
minlength / maxlengthLength of text.
min / max / stepRange of numbers and dates.
patternMust match a regular expression.
<form>
  <input type="text" name="username" required minlength="3" maxlength="15">
  <input type="email" name="email" required>
  <input type="tel" name="phone" pattern="03[0-9]{9}" title="Format: 03001234567">
  <input type="number" name="age" min="13" max="99">
  <button>Sign up</button>
</form>