validator-list
Version:
27 lines (26 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmailValidator = void 0;
const _ = require("lodash");
const base_validator_1 = require("./base-validator");
class EmailValidator extends base_validator_1.BaseValidator {
constructor(attributeLabel, value, options) {
super(attributeLabel, value, options);
this.pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
this.message = '{attribute} is not a valid email address.';
this.setOptions(options);
}
getOptionNameList(...childrenList) {
return super.getOptionNameList(...childrenList, []);
}
validate() {
if (!this.isAvailableForValidation()) {
return false;
}
if (!_.isString(this.value) || this.value.length > 320 || !this.pattern.test(this.value)) {
return this.message.replace('{attribute}', this.attributeLabel);
}
return false;
}
}
exports.EmailValidator = EmailValidator;