0

I have this code to filter a form field on a mobile device so that only numeric phone numbers are allowed:

$( document ).on( "keypress", ".numeric_only", function(e) {
  if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
             return false;
  }
}); 

The problem is, even with this it still allows people to enter characters like - or . especially on Android ..even if I allow only the numerical tel keyboard.

What am I doing wrong?

user1996496
  • 972
  • 2
  • 10
  • 24
  • Possible duplicate of [How to allow only numeric (0-9) in HTML inputbox using jQuery?](https://stackoverflow.com/questions/995183/how-to-allow-only-numeric-0-9-in-html-inputbox-using-jquery) – Terry Oct 08 '17 at 08:06
  • Did you try `e.preventDefault()` instead of return false? – Nir Tzezana Oct 08 '17 at 08:08

0 Answers0