0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Character filter for text inputs: block characters outside a preset or custom character class while the user formats freely. Presets for phone, date, card numbers, letters and more.
Overview
data-accept is a character filter for text inputs. Characters outside the allowed set are blocked as they are typed or pasted; everything else, including the order and the separators, is up to the user. Use data-mask instead when the value must have one fixed shape.
It works on text-like <input> types (text, tel, search and similar). It does not filter files: to limit a file picker, use the native acceptattribute on <input type="file"> (see data-upload).
Usage
Add a preset name or a bracketed character class. Say what is allowed in visible help text linked with aria-describedby, so people who miss a blocked keystroke know why.
Phone character filter
123456
<form-field><labelfor="phone">Phone</label><inputtype="text"id="phone"name="phone"data-accept="phone"autocomplete="tel"aria-describedby="phone-hint"><outputid="phone-hint"class="hint"for="phone">Digits, +, parentheses, hyphens and spaces.</output></form-field>
Allowed characters. An unknown preset or an invalid class logs a warning and leaves the input unfiltered.
data-accept-pattern
(set by the script)
—
The regex source in use, for your own scripts. Read-only.
inputmode
native
from the preset
Set from the preset (table below) unless you set it yourself.
Presets
Preset
Allowed characters
inputmode
digits
0-9
numeric
alpha
a-z A-Z (ASCII only: rejects é, ß, Ж)
text
letters
letters and combining marks in any script (\p{L}\p{M})
text
alphanum
a-z A-Z 0-9 (ASCII only)
text
phone
digits, + ( ) - and space
tel
date
digits, / - .
numeric
hex
0-9 a-f A-F
text
currency
digits, . ,
decimal
cc
digits, space, -
numeric
A custom class is compiled as a JavaScript RegExp in Unicode mode, so [\p{L}\p{N}] and characters outside the Basic Multilingual Plane (emoji, rare CJK) work. Each character is tested on its own.
Behaviour
Typing — an invalid character is blocked in beforeinput, so it never appears.
Paste — invalid characters are removed and the rest is inserted with execCommand('insertText'), which keeps undo working.
IME — filtering waits for compositionend, then strips anything invalid.
Fallback — where beforeinput cannot be cancelled, the input handler strips invalid characters and keeps the cursor after the kept text.
Prefilled values and reset — the starting value is filtered when the input is enhanced, and again after a form reset restores the default.
With data-mask — if both are on one input, data-mask wins and a console warning is logged.
data-accept adds no constraint validation. It sets no pattern, values set from script are not filtered, and nothing stops a request built by hand. Add pattern, minlength or required for the shape you need, and validate on the server.
Events
data-accept fires no events of its own. The native input event fires for accepted text as usual; a blocked keystroke fires nothing. When the paste fallback writes the value directly, it dispatches a bubbling input event so listeners still see the change.
Styling
No public hooks. data-accept only filters characters; the input keeps its normal input styles.
Accessibility
Blocked characters give no feedback, so describe the allowed characters in visible help text linked with aria-describedby (an <output class="hint"> in <form-field>). A placeholder is not a reliable description: it disappears on input and is often not announced.
inputmode from the preset brings up a fitting on-screen keyboard.
IME composition is never interrupted.
Use letters, not alpha, for names: alpha rejects letters outside A–Z.
Without JavaScript the input accepts any text.
Examples
Custom character class with a pattern
The filter keeps out other characters; pattern makes the form require exactly six.
Custom class plus pattern
123456
<form-field><labelfor="hex">Hex colour</label><inputtype="text"id="hex"name="hex"data-accept="[0-9a-fA-F]"maxlength="6"pattern="[0-9a-fA-F]{6}"aria-describedby="hex-hint"><outputid="hex-hint"class="hint"for="hex">Six characters, 0–9 and A–F.</output></form-field>
All presets, paste and data-mask side by side
Flexible versus fixed phone format
1234567
<!-- data-accept: the user picks the format --><labelfor="accept-phone">Type any valid phone format</label><inputtype="text"id="accept-phone"data-accept="phone"><!-- data-mask: one fixed format, separators inserted --><labelfor="mask-phone">Auto-formatted phone</label><inputtype="tel"id="mask-phone"data-mask="phone">
data-accept or data-mask?
data-accept
data-mask
Separators
Typed by the user
Inserted for the user
Format
Any order of allowed characters
One fixed shape
Use when
Several formats are valid
You define the format
Related
data-mask — fixed-format input with inserted separators. Choose it when there is exactly one valid shape.
<input> — native pattern, inputmode and, for files, accept.
<form-field> — label, hint and validation messages around the input.
data-upload — file drop zone; file types are limited by the native acceptattribute, not data-accept.
accept — the native file-type attribute on file inputs, which is unrelated to data-accept.
inputmode — choose the keyboard to match the characters you allow.