I have requirement to avoid numeric input in a text type input field. My application is used only in devices like iPhone and Android.
For which I tried using the below code:
$("#custName-info").keypress(function (event) {
alert(event.charCode);
var inputValue = event.charCode;
if (!(inputValue >= 65 && inputValue <= 120) && (inputValue != 32 && inputValue != 0)) {
event.preventDefault();
}
});
Here, the code works perfectly fine with iPhone but it doesn't work in Android devices. on investigating it, I found below information:
- keypress is deprecated and hence should be avoided to be used. But if that is the reason, why is it working with my iPhone or on Chrome device emulator?
- People have suggested to use either of the three below substitute event:
keyup, keydown, input, change
- I further found that the any of these 3 events doesnt work for me in devices because they do not give me
charCode
to identify the numeric inputs. - There was something on
keyCode
but then I couldnt understand what is the difference incharCode
andkeyCode
So my final word on this question is, "how can I can prevent user to input numerics in the text field? Web Application being used in iPhone and Android devices".