Skip to content

Instantly share code, notes, and snippets.

@AdonaiAraya
Last active May 20, 2016 09:29
Show Gist options
  • Save AdonaiAraya/4f49045d171d0d922f08e20388667713 to your computer and use it in GitHub Desktop.
Save AdonaiAraya/4f49045d171d0d922f08e20388667713 to your computer and use it in GitHub Desktop.
Angular directive for min digits validation in input type number
/*
<input type='number' min-digits='4' />
*/
.directive("minDigits", function () {
return {
require: "ngModel",
link: function (scope, element, attrs, ctrl) {
var min = attrs.minDigits;
element.bind("keyup", function () {
var currentValue = element.val();
var v = currentValue.length >= min;
scope.$apply(function () {
ctrl.$setValidity("mindigits", v);
});
});
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment