Input field should allow only numbers from 0-9, if not number the value entered should not even display in the field. I have tried achieving this using directive which uses $parsers
app.directive('onlyNumber', function() {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function(inputValue) {
if (inputValue == null)
return ''
cleanInputValue = inputValue.replace(/[^\w\s]/gi, '');
if (cleanInputValue != inputValue) {
modelCtrl.$setViewValue(cleanInputValue);
modelCtrl.$render();
}
return cleanInputValue;
});
}
}
});
This allows characters, and restricts only special characters, I want restric anything other than number.