Validated Inputs
Input components with built-in validation. The client-side validators below run entirely in the browser (no round-trip); the older components further down call server endpoints on blur.
Client-side validators (live)
Wired declaratively with data-validate="<name>" (see static/js/validation.js). These validate on every keystroke and on blur, with three behaviors:
- Partial: a good-so-far but incomplete value stays neutral while typing, and is only rejected when you leave the field.
- Eager fail: the instant a value can never become valid (e.g. a
Win a Roman numeral, a letter in an integer), it fails immediately — no need to blur. - Normalize on blur: valid values are rewritten to canonical form when you leave the field.
Date Picker
Uses the browser's native date picker. Accepts ISO (YYYY-MM-DD) or US (MM/DD/YYYY) format.
Time Input
Accepts both 24-hour (14:30) and 12-hour (2:30 PM) formats. Invalid mixed formats like "13:22 PM" are rejected.
DateTime Picker
Combines date and time inputs. Both are validated independently.
Number Input
Accepts integers, decimals, and scientific notation. The input uses a text field for unlimited precision.
Phone Number
Accepts any common phone format. Strips non-digit characters and normalizes to XXX-XXX-XXXX. A leading US country code (1) is dropped.
Email Address
Accepts any string with exactly one @ and non-empty text on both sides. Normalizes by trimming whitespace (case preserved).
Roman Numeral
Accepts an Arabic integer (1-9999) or a Roman numeral (case-insensitive) and normalizes to a canonical uppercase Roman numeral. Non-canonical input like IIII is accepted and re-emitted as IV.
How It Works
Validation Flow
- User enters a value and blurs (leaves) the input
- HTMX sends a POST request to
/validate/{type} - Server validates and returns JSON:
{"valid": true, "normalized": "..."}or{"valid": false, "error": "..."} - JavaScript updates the input state (green/red border) and shows any error message
- If valid, the input value is updated to the normalized form
Server Endpoints
POST /validate/date- Validates date stringsPOST /validate/time- Validates time stringsPOST /validate/datetime- Validates datetime stringsPOST /validate/number- Validates number stringsPOST /validate/phone- Validates & normalizes phone numbersPOST /validate/email- Validates email addressesPOST /validate/roman- Validates & canonicalizes Roman numerals
All endpoints accept form data with a value field and return JSON.