Javascript: Decimals still being allowed in regex check for numbers [duplicate]

if you want only integers, use:

/^-?\d+$/.test(v)

— EXPLANATION

^ – start of the string

-? – minus in the start, ? means can be but not necessary

\d – any number (including zero)

+ – the last expression (=any number) can repeat more then once

$ – end of the string

Leave a Comment