Skip to content

Instantly share code, notes, and snippets.

@mcraz
Last active December 31, 2015 10:58
Show Gist options
  • Save mcraz/7976178 to your computer and use it in GitHub Desktop.
Save mcraz/7976178 to your computer and use it in GitHub Desktop.
Accept numeric input only using JavaScript
onkeypress="if ( isNaN( String.fromCharCode(event.keyCode) )) return false;"
Example Use : <input type="text" name="length" value="" class="form-control " placeholder="Video Duration (in seconds)" autocomplete="off" onkeypress="if ( isNaN( String.fromCharCode(event.keyCode) )) return false;">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment