Skip to content

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

type IsAllowed = (rawValue: string) => boolean

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

<NumoraInput
  isAllowed={(raw) => {
    // Half-typed values. "-" and "-." only arrive with allowNegative
    if (raw === '' || raw === '-' || raw === '.' || raw === '-.') return true
    const n = parseFloat(raw) // comparison only
    return Number.isFinite(n) && n <= 100
  }}
/>

Example: whole numbers, up to 6 digits

This predicate is safe for every prefix, so users can type and delete freely.

<NumoraInput
  isAllowed={(raw) => /^\d{0,6}$/.test(raw)}
/>

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 value and defaultValue props, option changes and the ref's setValue() are never checked
  • Does not run when blur settles the value. If blur turns 1. into 1 or pads 1.5 to 1.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.

PropInvalid whenError message
maxLengthNot a whole number of 1 or moremaxLength must be a positive integer (>= 1). Received: 0
decimalMaxLengthNot a whole number of 0 or moredecimalMaxLength must be a non-negative integer. Received: -1
decimalMinLengthNot a whole number of 0 or moredecimalMinLength must be a non-negative integer. Received: -1
decimalMinLengthGreater than decimalMaxLengthdecimalMinLength (3) cannot be greater than decimalMaxLength (2).
formatOnNot 'blur' or 'change'formatOn must be one of: 'blur', 'change'. Received: "input"
groupingStyleNot one of the four stylesgroupingStyle must be one of: 'none', 'thousand', 'lakh', 'wan'. Received: "indian"
thousandSeparatorAn empty stringthousandSeparator cannot be empty. Use groupingStyle: 'none'.
thousandSeparator, decimalSeparatorLonger than one character. For decimalSeparator, also an empty stringdecimalSeparator must be a single character. Received: ", "
thousandSeparator, decimalSeparatorA digitthousandSeparator cannot be a digit. Received: "1"
thousandSeparator, decimalSeparatorOne of - + e E k K m M b B t TthousandSeparator cannot be one of the reserved characters -+eEkKmMbBtT (sign, exponent, or compact-notation suffix). Received: "k"
thousandSeparator, decimalSeparatorBoth passed, as the same characterdecimalSeparator cannot equal thousandSeparator. Both were ".".
allowNegative, allowLeadingZeros, allowCompactNotation, allowScientificNotation, padLeadingZeroNot a booleanallowNegative must be a boolean. Received: "yes"
isAllowed, onValueChange, onFormattedValueChangeNot a functionisAllowed must be a function. Received: "x"
localeA string that is not a BCP 47 taglocale 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 locale tag the runtime does not know. The runtime picks its closest match.
  • A removed v4 prop such as thousandStyle or maxDecimals. Numora ignores it and, in development, warns with the name of its replacement. The migration guide lists every one.