AngularJS: ngModel $parsers.
HTML
<div ng-app="myApp" ng-controller="MainCtrl">
<input test="" type="text" ng-model="model"/>{{model}}
</div>
JavaScript
var app = angular.module('myApp', []);
app.controller('MainCtrl', function($scope) {
});
app.directive('test', function() {
return {
require: '^ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(value) {
ngModel.$viewValue="123";
ngModel.$render();
return value.replace(/\D/g, '');
});
}
};
});