Skip to content

Instantly share code, notes, and snippets.

@anshuraj
Created May 1, 2018 06:11
Show Gist options
  • Save anshuraj/622066b3bdd1edeb276579e38d54f509 to your computer and use it in GitHub Desktop.
Save anshuraj/622066b3bdd1edeb276579e38d54f509 to your computer and use it in GitHub Desktop.
input field restrict to 2 digits after decimal
$('.decimal').keypress(function (e) {
var character = String.fromCharCode(e.keyCode)
var newValue = this.value + character;
if(newValue.toString().split('.')[1].length > 2) {
e.preventDefault();
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment