Created
February 22, 2014 08:05
-
-
Save KazChe/9150293 to your computer and use it in GitHub Desktop.
This file contains 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('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