Validation
An isAllowed predicate rejects edits the user makes (typing, deleting, paste, drop, autofill, IME) before they commit. Use it for business rules or format constraints that don't fit a built-in option.
setValue('500')500
A value set from code is never checked
rawValue is the sanitized, raw (no-separator) string that would be committed. Return true to accept it, false to discard it. The input keeps its previous value and no onValueChange fires.
Example: cap at 100
Example: whole numbers, up to 6 digits
Notes
- Runs after sanitization and formatting. For typing and paste that is before the DOM is mutated. For drop, autofill and IME text, which the browser has already inserted, a rejection puts the previous value back
- Fires for typing, deletion, paste, drop, autofill and IME text. A keystroke that changes nothing, or one a built-in option already refused, never reaches it
- Does not run for values your code writes:
defaultValue,setValue()andupdate()are never checked - Does not run when blur settles the value. If blur turns
1.into1or pads1.5to1.50, the settled value is not checked - A predicate that throws counts as a rejection, and the error is logged with
console.error - Always allow the intermediate strings users need to type their way to a valid value (empty string, lone
-or decimal separator) - Keep the predicate cheap, because it runs on every edit
- For length and decimal-precision caps, use max length and decimals instead
Invalid options
Numora checks every option in the constructor and in update(). An invalid one throws an Error. A failed update() leaves the field with its old options.
| Option | Invalid when | Error message |
|---|---|---|
maxLength | Not a whole number of 1 or more | maxLength must be a positive integer (>= 1). Received: 0 |
decimalMaxLength | Not a whole number of 0 or more | decimalMaxLength must be a non-negative integer. Received: -1 |
decimalMinLength | Not a whole number of 0 or more | decimalMinLength must be a non-negative integer. Received: -1 |
decimalMinLength | Greater than decimalMaxLength | decimalMinLength (3) cannot be greater than decimalMaxLength (2). |
formatOn | Not 'blur' or 'change' | formatOn must be one of: 'blur', 'change'. Received: "input" |
groupingStyle | Not one of the four styles | groupingStyle must be one of: 'none', 'thousand', 'lakh', 'wan'. Received: "indian" |
thousandSeparator | An empty string | thousandSeparator cannot be empty. Use groupingStyle: 'none'. |
thousandSeparator, decimalSeparator | Longer than one character. For decimalSeparator, also an empty string | decimalSeparator must be a single character. Received: ", " |
thousandSeparator, decimalSeparator | A digit | thousandSeparator cannot be a digit. Received: "1" |
thousandSeparator, decimalSeparator | One of - + e E k K m M b B t T | thousandSeparator cannot be one of the reserved characters -+eEkKmMbBtT (sign, exponent, or compact-notation suffix). Received: "k" |
thousandSeparator, decimalSeparator | Both passed, as the same character | decimalSeparator cannot equal thousandSeparator. Both were ".". |
allowNegative, allowLeadingZeros, allowCompactNotation, allowScientificNotation, padLeadingZero | Not a boolean | allowNegative must be a boolean. Received: "yes" |
isAllowed, onValueChange, onFormattedValueChange | Not a function | isAllowed must be a function. Received: "x" |
locale | A string that is not a BCP 47 tag | locale must be a BCP 47 tag such as "de-DE". Received: "not a tag" |
These never throw:
- One separator passed alone. If it lands on the other separator, the other one switches between
.and,. - A well-formed
localetag the runtime does not know. The runtime picks its closest match. - A removed v4 option such as
thousandStyleormaxDecimals. Numora ignores it and, in development, warns with the name of its replacement. The migration guide lists every one.