Skip to content

Instantly share code, notes, and snippets.

@KazChe
Created February 22, 2014 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KazChe/9150293 to your computer and use it in GitHub Desktop.
Save KazChe/9150293 to your computer and use it in GitHub Desktop.
angular.module('angularstruts').directive('hexadecimalColorValidation', [function(){
return {
restrict: 'A',
require: 'ngModel',
scope: {
},
link: function(scope, elem, attrs, ctrl) {
elem.on('blur', function(event) {
scope.$apply(function() {
var val, hexCodeRegex, validationResult=true;
val = elem.val();
hexCodeRegex = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
validationResult = hexCodeRegex.test(val);
ctrl.$setValidity('validHexColor', validationResult);
})
})
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment