Created
June 25, 2014 11:10
-
-
Save OzieWest/1345e4fc9a0a2dc414ee to your computer and use it in GitHub Desktop.
Только цифры в input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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