<input type="number"> restricting user input to only valid characters

With <input type="number">, if a user enters "abc" for example, the specs  
says to handle that as if the value is an empty string.

However, should the UA even allow the user to enter those characters in  
the field? It seems like if the keypress is not one of "-+.e0123456789"  
(or "," instead of "." depending on the locale), then the keypress should  
be prevented. Or, if a value that's pasted into the field that's invalid  
should be prevented.

Or, is validation only meant for when it's time to submit?

Now, with JS, you might be able to do this with listening for keypress and  
preventing it. But, to catch all kinds of input, you'd need to use the  
'input' event or the 'change' event. But, those don't seem to be  
cancelable. You could revert the value though if the user inputs something  
invalid. Seems like the UA should do this though.

Or, is this one of things where "The UA can do whatever it wants"? If so,  
is there any common practice that should be followed with user input in  
this case?

-- 
Michael

Received on Friday, 19 June 2009 19:57:19 UTC