Reputation: 37
i want one textbox which only accpet the number, this solution i need without html5 support.
i have textbox inside the custom directive template.
ng-keypress="Validation($event)"
and
in controller of that directive, i wrote like this :
$scope.Validation = function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
}
but it is not working, any idea?
Upvotes: 0
Views: 75
Reputation: 591
Just add the following line before the return false;
:
e.preventDefault();
This will prevent the keypress event propagation and will cancel the user's input.
Upvotes: 1