🚸 (number) Avoid parsing numbers starting with 0
This commit is contained in:
@@ -1 +1,4 @@
|
||||
export const parseNumber = (value: string) => Number(value).toString()
|
||||
export const parseNumber = (value: string) => {
|
||||
if (value.startsWith('0')) return value
|
||||
return parseFloat(value).toString()
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ export const validateNumber = (
|
||||
variables: Variable[]
|
||||
}
|
||||
) => {
|
||||
if (inputValue === '') return false
|
||||
|
||||
const parsedNumber = Number(inputValue)
|
||||
if (isNaN(parsedNumber)) return false
|
||||
|
||||
const min =
|
||||
options?.min && typeof options.min === 'string'
|
||||
? Number(parseVariables(variables)(options.min))
|
||||
@@ -20,10 +25,8 @@ export const validateNumber = (
|
||||
options?.min && typeof options.min === 'string'
|
||||
? Number(parseVariables(variables)(options.min))
|
||||
: undefined
|
||||
|
||||
return (
|
||||
inputValue !== '' &&
|
||||
(isNotDefined(min) || Number(inputValue) >= min) &&
|
||||
(isNotDefined(max) || Number(inputValue) <= max)
|
||||
(isNotDefined(min) || parsedNumber >= min) &&
|
||||
(isNotDefined(max) || parsedNumber <= max)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user