I'm trying to override the e-mail validator from AngularJS, but I can't seem to get it to work properly.
This is the code that I have for the JavaScript file:
var app = angular.module("home", []);
app.directive("overwriteEmail", function() {
var UEMAIL_REGEX = /^[a-z0-9]+@university\.edu$/i;
return {
require: "ngModel",
restrict: "",
link: function(scope, elm, attrs, ctrl) {
if (ctrl && ctrl.$validators.email) {
ctrl.$validators.email = function(modelValue) {
return ctrl.$isEmpty(modelValue) || UEMAIL_REGEX.test(modelValue);
};
}
}
};
});
For the HTML file I have this:
<label>University Email Address:</label>
<input type="email" overwrite-email name="uemail" data-ng-model="email" placeholder="University e-mail required" required>
<span class="warning" data-ng-show="regis.uemail.$error.email">Invalid email!</span>
My code validates up to the @ sign, then it doesn't seem to care what comes after the @ symbol. What approach can I take to fix this problem?