Skip to content

Instantly share code, notes, and snippets.

@OzieWest
Created June 25, 2014 11:10
Show Gist options
  • Select an option

  • Save OzieWest/1345e4fc9a0a2dc414ee to your computer and use it in GitHub Desktop.

Select an option

Save OzieWest/1345e4fc9a0a2dc414ee to your computer and use it in GitHub Desktop.
Только цифры в input
angular.module('myApp', []).directive('numbersOnly', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function (inputValue) {
if (inputValue == undefined) return ''
var transformedInput = inputValue.replace(/[^0-9]/g, '');
if (transformedInput!=inputValue) {
modelCtrl.$setViewValue(transformedInput);
modelCtrl.$render();
}
return transformedInput;
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment