I want user to allows only numbers to be typed into a textbox.
For this I am using below code :

```
.directive('digitOnly', [function () {
    return {
        require: 'ngModel',
        scope: {
            digitOnly: '=?'
        },
        link: function (scope, element, attrs, modelCtrl) {
            if (scope.digitOnly || scope.digitOnly == undefined) {
                modelCtrl.$parsers.push(function (inputValue) {
                    if (inputValue == undefined) return '';
                    if (attrs.digitOnly == "false") {
                        return inputValue;
                    } else {
                        var transformedInput = inputValue.replace(/[^0-9]/g, '');
                        if (transformedInput != inputValue) {
                            modelCtrl.$setViewValue(transformedInput);
                            modelCtrl.$render();
                        }
                        return transformedInput;
                    }
                });
            }
        }
    };
}])

```

My input textbox code is given below :

```
<input type="text" name="sidNo" class="form-input" placeholder="Enter 5-6 digits"
ng-minlength="5" maxlength="6" ng-model="profInfo.sidNo" required digit-only
ng-pattern="/^[0-9]*$/">

```

It is working fine when I type anything. It restrict me to type except numbers.

But the problem is that when my ng-model value profInfo.sidNo comes from backend like `AASS001` that is showing me on textbox as invalid input error message that is correct but when I remove this value from backspace button it remove all value on single key press of backspace and input two Zeros like `00`

So please help me to fix this.

I am using AngularJS.