vUX / FormValidator / v4.1.0
Write each field's rules as a small object. FormValidator checks them in a fixed order, puts the first failure under or beside the field, and submits the form behind its own loader. Leave a field, or press Create account.
Write a message straight onto the field, run your own rules through validate(),
recolour the boxes, pick a loader and submit. Settings that initialize() reads
rebuild the validator; the rest apply to the running one.
The boxes read --error-color, --error-background-color,
--error-border-color and the warning and success pairs. Set them on a form and
only that form changes. Both cards below run the same three message.write() calls.
#themeViolet{ --error-color:#f0d4ff; --error-background-color:#2b1840; --error-border-color:#c8a2ff; --warning-color:#b9f3ff; --warning-background-color:#0f2a33; --warning-border-color:#5ccfe6; --success-color:#101a06; --success-background-color:#a7e05f; --success-border-color:#c8f08f; }
FormValidator.format is static: no instance, no initialize().
Groups the whole part only, keeps the sign and the decimals, and returns a string.
Rounds through exponent notation, so 1.005 becomes 1.01, not 1.
Strips every non-digit as it is typed. Paste +1 (555) 010-99 and see.
On blur, joins the words with the separator repeated n times. Here "-", twice.
The constructor, every setter and every method check their arguments. Each button runs one bad call on a fresh validator and prints what it threw.
Two checks are lazy, and the last two buttons show it: validate() checks
location only when it writes a message, and a size rule is parsed only when a file is chosen.