An issue has arisen with my directive that is meant to validate an input field to ensure it does not include the characters &
, <
, >
.directive('refValidate', [function () {
var regExp = /^[&\<\> ]*$/;
return {
require: 'ngModel',
link: function(scope, elem, attr, ctrl) {
function myValidation(value) {
if (!regExp.test(value)) {
ctrl.$setValidity('validRef', true);
} else {
ctrl.$setValidity('validRef', false);
}
return value;
}
ctrl.$parsers.push(myValidation);
}
};
}]);
The current functionality only returns false if the specified characters are at the beginning of the value, but I need it to check if they are present anywhere in the value.
Query
What adjustments do I make to my regular expression to ensure it checks for the specified characters anywhere in the input value?