I have a form with an input such as this:
<form>
<input type='number' id='nb'>
</form>
Now, the issue is the following:
When a user inputs an invalid number, I can't get the raw input to try and fix it myself.
For example, depending on the locale, the following numbers can be invalid:
400 000
43,2
43.2
The first one can come from a copy/paste, the other 2 from a misconfiguration of the device, or the use of a device not configured in the users native language.
I have tried to add novalidate
to the form and to the input, it does not change anything.
I know that input.validity.valid
returns false and that usually input.validity.badInput
will be true, so I can display a message to the user, but the message can be unspecific and confusing, especially since the decimal point issue can easily be identified and fixed, and it is quite commonly seen during field tests.
I have tried to change the type of the input dynamically (so it displays a keypad on mobile devices), but every time I change the type, the value is cleared.
I have considered preventing the input of invalid chars by intercepting keydown
events, but that does not solve copy-paste issue.
I have also considered tracking the complete input, but that is unreasonable considering all the possible cases of inputs (to mention only copy-pasting).
I have read this question, but I am not satisfied with the answer. The input is on the screen, I can see it, I don't see what good reason there could be that I cannot read it.
Edit
jsfiddle : http://jsfiddle.net/AXu92/