Validation
Use an isAllowed predicate to reject edits the user makes (typing, deleting, paste, drop, autofill, IME) before they commit. It fits business rules and format rules that no built-in prop covers.
value="500"The value prop is never checked
rawValue is the sanitized, raw (no-separator) string that would be committed. Return true to accept it or false to discard it. A discarded value leaves the input at its previous value, and neither onChange nor onValueChange fires.
Example: cap at 100
Reject anything above 100
Try typing past 100. Keystrokes that would exceed it are blocked
Example: whole numbers, up to 6 digits
This predicate is safe for every prefix, so users can type and delete freely.
Notes
- Runs after sanitization and formatting. For typing and paste that is before the DOM is mutated and React state updates. 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: the
valueanddefaultValueprops, option changes and the ref'ssetValue()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 React checks every prop before it uses it. In development an invalid prop throws during render. In production it logs the error with console.error and the field keeps its last valid options, or the defaults on a first render.
| Prop | 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 prop such as
thousandStyleormaxDecimals. Numora ignores it and, in development, warns with the name of its replacement. The migration guide lists every one.