W3C home > Mailing lists > Public > public-html@w3.org > June 2009

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

From: Michael A. Puls II <shadow2531@gmail.com>
Date: Fri, 19 Jun 2009 15:56:39 -0400
To: public-html@w3.org
Message-ID: <op.uvse0pwi1ejg13@sandra-svwliu01>
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?

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

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:46 UTC