How do I make this field accept only binary numbers that do not accept 12 or 13 and etc., just numbers 1 and 0, such as 0000111 or 1000 or 11111 ??
How do I make this field accept only binary numbers that do not accept 12 or 13 and etc., just numbers 1 and 0, such as 0000111 or 1000 or 11111 ??
function SomenteNumero(e){
var tecla=(window.event)?event.keyCode:e.which;
if((tecla==48 || tecla==49)) return true;
else{
return false;
}
}
<input type="text" size="10" value=""' onkeypress="return SomenteNumero(event);">
I noticed that keyCode is now obsolete and will be discarded:
I tested with e.key
function SomenteNumero(e){
var tecla=(window.event)?e.key:e.which;
if((tecla==48 || tecla==49)) return true;
else{
return false;
}
}
<input type="text" size="70" value=""' onkeypress="return SomenteNumero(event);">
in modern browsers.