Closed cferdinandi closed 6 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+)$/
This is a fallback for browsers that do not support number
.
^[\d]*$