Add angular directive for domain validation input fields
This commit is contained in:
@@ -470,3 +470,35 @@ app.directive('tagInput', function () {
|
||||
'</div>'
|
||||
};
|
||||
});
|
||||
|
||||
app.directive('domainValidator', function() {
|
||||
return {
|
||||
|
||||
// limit usage to argument only
|
||||
restrict: 'A',
|
||||
|
||||
// require NgModelController, i.e. require a controller of ngModel directive
|
||||
require: 'ngModel',
|
||||
|
||||
// create linking function and pass in our NgModelController as a 4th argument
|
||||
link: function(scope, element, attr, ngModel) {
|
||||
function validator(value) {
|
||||
|
||||
if (value.indexOf('.cloudron.') === -1 && /^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})$/.test(value)) {
|
||||
ngModel.$setValidity('invalidDomain', true);
|
||||
} else {
|
||||
ngModel.$setValidity('invalidDomain', false);
|
||||
}
|
||||
|
||||
// we need to return our value, to be displayed to the user(value of the input)
|
||||
return value ? value : undefined;
|
||||
}
|
||||
|
||||
//For DOM -> model validation
|
||||
ngModel.$parsers.unshift(validator);
|
||||
|
||||
//For model -> DOM validation
|
||||
ngModel.$formatters.unshift(validator);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user