I have found great many occurrences of the following pattern for html inputs, this being for phone numbers:
You can try this approach:
.directive('bkNgValidation', function () {
return: {
link: function (scope, element, attrs) {
if (attrs['bk-ng-validation'] === 'phoneNumber') {
element.$validateModel(function (value, validator) {
if (value.length < 10 || value.length > 15) {
validator.$setValidity('phone', true);
} else {
validator.$setValidity('phone', false);
}
});
}
}
}
})