[whatwg] Web Forms 2.0 proposal
shogun70 at westnet.com.au
Fri Feb 10 14:43:41 PST 2006
Ian Hickson wrote:
>On Sat, 11 Feb 2006, Sean Hogan wrote:
>>I would request a input filter as a regex range eg a-zA-Z0-9 i.e. if
>>the keyCode is NOT within the range then preventDefault(). I imagine
>>that number, date, datetime, etc will be special implementations that
>>filter keyboard input. Why not extend the facility to text, etc?
>This is already possible using the pattern="" attribute:
I expressed myself poorly.
If I'm reading the spec correctly then "pattern" is used to
prevent/allow form submission, and to highlight an invalid entry.
What I am suggesting is a filter that can be matched against for each
If keyCode matches then the character is appended to the input as normal.
If it doesn't then the character is dropped on the floor.
Here is some code which may be correct for current W3C browsers.
The intention here is to only accept alphanumeric characters.
<input type="text" filter="a-zA-Z0-9" onkeypress="inputfilter" />
var n = e.keyCode || e.which; // keyCode is 0 for mozilla. use
if (n==8 || n==9 || n==16 || n==17 || n==37 || n==39 || n==46)
return true; // don't filter control characters
var str = String.fromCharCode(n);
var filter = this.getAttribute("filter");
var r = new RegExp("["+filter+"]");
if (r.test(str)) return true;
On second thoughts, it probably isn't a good idea to put this in the
It is probably within the same realm as spell checking and
More information about the whatwg