Created
July 17, 2019 09:36
-
-
Save Lodo4ka/dd68bf00433b7d56490dcb67e86887b2 to your computer and use it in GitHub Desktop.
custom directive angularjs for replace input with only numbers
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
| (function() { | |
| angular.module("BauVoiceApp").directive("customValidation", function() { | |
| return { | |
| require: "ngModel", | |
| link: function(scope, element, attrs, modelCtrl) { | |
| modelCtrl.$parsers.push(function(inputValue) { | |
| const numberPattern = /\d+/g; | |
| let transformedInput = inputValue.match(numberPattern)[0]; | |
| 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