I want to ignore certain characters in my phone input, so that the database just has digits. I know I can do this easy on server side (using PHP) but I am trying to understa
I had to do something similar for a project I'm working on. This is how I did it.
// prevent users from typing alpha/ symbol characters on select fields
$("#modal-region").on("keydown", "#markdown, #sku", function(e) {
var key = e.which;
// when a keydown event occurs on the 0-9 keys the value
// of the "which" property is between 48 - 57
// therefore anything with a value greater than 57 is NOT a numeric key
if ( key > 57) {
e.preventDefault();
} else if (key < 48) {
// we don't want to disable left arrow (37), right arrow (39), delete (8) or tab (9)
// otherwise the use cannot correct their entry or tab into the next field!
if (key != 8 && key != 9 && key != 37 && key != 39 ) {
e.preventDefault();
}
}
});