Patterns and custom messages in HTML
A regular expression on the field, checked before anything is sent.
<label for="sku">Product code</label>
<input type="text" id="sku" name="sku"
pattern="[A-Z]{2}-[0-9]{3}"
title="Two letters, a hyphen, three digits"
placeholder="TS-001" required>
<label for="pin">PIN</label>
<input type="text" id="pin" name="pin" pattern="[0-9]{4}"
inputmode="numeric" autocomplete="one-time-code"
title="Four digits">
How it works
patternmust match the whole value; no anchors are needed.titleis what the browser shows when the pattern fails.inputmodepicks the on-screen keyboard without changing validation.
The run, in numbers
- Lines
- 10
- Characters to type
- 337
- Tokens
- 68
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 54 seconds.
Step 2 of 5 in Validation & submission, step 20 of 25 in Forms & inputs.