0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.