cferdinandi / validate

A lightweight form validation script.
MIT License
230 stars 39 forks source link

Update integer regex #20

Closed cferdinandi closed 6 years ago

cferdinandi commented 7 years ago

^[\d]*$

FloEdelmann commented 7 years ago

Actually, this will not work: https://stackoverflow.com/questions/18852244/how-to-get-the-raw-value-an-input-type-number-field

If the browser natively supports the <input type="number" /> element, its value property will be set to an empty string until a valid number is entered. So it is impossible to catch this case.

A workaround could be to listen to the browser's own validityState and use it as a fallback.


Apart from that, the RegEx should actually be /^[-+]?(?:\d+|\d*[.,]\d+)$/

cferdinandi commented 7 years ago

This is a fallback for browsers that do not support number.