This PR modifies the NumberSchema to enhance number validation, addressing an issue where strings with internal whitespace (e.g., "9 9") were incorrectly passing validation.
Changes:
Updated the transform function in the NumberSchema constructor to:
Trim leading and trailing whitespace from string inputs
Use a regular expression to strictly validate the number format
Reject strings with internal whitespace or non-numeric characters
Behavior changes:
"99 " and " 99" now pass validation (trimmed to 99)
"9 9" now fails validation (becomes NaN)
"9.9" continues to pass validation (becomes 9.9)
"9,9" now fails validation (becomes NaN)
Implementation details:
parsed = parsed.trim();
if (!/^\d+(\.\d+)?$/.test(parsed)) return NaN;
Description
This PR modifies the NumberSchema to enhance number validation, addressing an issue where strings with internal whitespace (e.g., "9 9") were incorrectly passing validation.
Changes:
transform
function in the NumberSchema constructor to:Behavior changes:
Implementation details: