Skip to content

Instantly share code, notes, and snippets.

@zubayerahamed
Created February 21, 2018 18:00
Show Gist options
  • Save zubayerahamed/3f736185270330341d3df8e459a7b985 to your computer and use it in GitHub Desktop.
Save zubayerahamed/3f736185270330341d3df8e459a7b985 to your computer and use it in GitHub Desktop.
How to allow only numeric (0-9) in HTML inputbox using jQuery?
$('#smsAmount').on('keydown', '#child', function(e){-1!==$.inArray(e.keyCode,[46,8,9,27,13,110,190])||(/65|67|86|88/.test(e.keyCode)&&(e.ctrlKey===true||e.metaKey===true))&&(!0===e.ctrlKey||!0===e.metaKey)||35<=e.keyCode&&40>=e.keyCode||(e.shiftKey||48>e.keyCode||57<e.keyCode)&&(96>e.keyCode||105<e.keyCode)&&e.preventDefault()});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment