function keyDown()
{
alert("KeydownEvent Fired");
}
function keypress()
{
alert("keypress Event Fired")
}
function keyup()
{
alert("key up event fired");
}
function onlyAlphabets(e) {
debugger;
try {
if (window.event) {
var charCode = window.event.keyCode;
}
else if (e) {
var charCode = e.which;
}
else { return true; }
var keyCodes = [13, 16, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 91, 92, 93, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 144, 145];
if (keyCodes.indexOf(charCode) != -1) {
return false;
}
else if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 8 || charCode == 32 || charCode == 9 || charCode == 46 || charCode == 37 || charCode == 39 || charCode == 16 || charCode == 17)
return true;
else
return false;
}
catch (err) {
alert(err.Description);
}
}
<input type="textbox" placeholder="Keydown" onkeydown="return onlyAlphabets(event,this);"></input>
</br>
<input type="textbox" placeholder="Keypress" onkeypress="keypress()"></input>
</br>
<input type="textbox" placeholder="Keyup" onkeyup="keyup()"></input>
</br>
This is just a piece of code.
I have include a some input tags which all have Different keypress events and then I have uploaded it to live, it working fine in all the browser's, but when I try to open my page in Mobile or tablet it is not working fine.
Even if alerts are working in Browsers but i have kept a validation for first name on keydown that user can only enter alphabets(numeric and special character not allowed)