Max length
Max length caps the input by raw character count, so thousand separators are excluded. The native maxLength attribute counts formatted characters: 1,234,567 is 9 characters but only 7 digits, and Numora counts 7.
maxLength: 4A paste is cut to 4 digits
Rules
- Counts the raw value after sanitization. Thousand separators and
decimalMinLengthpadding are excluded - The decimal separator is counted, because it is part of the raw value
- A leading
-sign is counted - Numora truncates from the right. If that would leave a trailing decimal separator, it removes the separator too (
"1234.56"capped at 5 →"1234") - If truncation would leave a bare
"-", the result is"" - The cut comes before the decimals are trimmed to
decimalMaxLength. WithmaxLength: 4, a pasted1.23456789becomes1.23, a pasted123456becomes1234, and a pasted123.456becomes123 maxLengthmust be a whole number of 1 or more. See invalid options
Pasted values
Numora truncates a paste after sanitizing it. Pasting "99999999" into an input with maxLength: 4 commits "9999".
Typing is different. A keystroke that would take the raw value past the limit is rejected, and nothing is cut. Values your code passes in are truncated like a paste.
Truncation happens after compact and scientific notation expand, so it can change the magnitude. With allowCompactNotation and maxLength: 5, a pasted 1.5m expands to 1500000 and is cut to 15000. To refuse an over-long paste, drop maxLength and check the length in isAllowed. With both set, isAllowed only sees the value after it was cut.
Standalone utility
To truncate a string outside the input pipeline, import truncateToMaxLength from the numora/pipeline entry point: