What I have to do is not permit to introduce number characters in a text input in a form, but I've to do it with javascript. Here's my HTML code:
<form id="formu">
<input type="text" id="num" />
</form>
And here's my JS code:
function numero(theEvent){
var evento=theEvent||window.event;
switch(evento.type){
case 'keypress':
if(document.getElementById("num").evento.keyCode>=48&&document.getElementById("num").evento.keyCode<=57){
return false;
}
}
}
You can use the new pattern attrib HTML ,
<input type="text" id="num" pattern="[A-Za-z]" title="Only Alphabets">
function validateKeyStrokes(event) {
var charCode = (event.which) ? event.which : event.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
<form id="formu">
<input type="text" id="num" onkeypress="return validateKeyStrokes(event)" />
</form>
Try this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With