2016-04-15 17:45:50 +03:00
|
|
|
import BaseValidator from './base';
|
2019-01-22 16:09:38 +03:00
|
|
|
import validator from 'validator';
|
2018-03-19 20:56:09 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
2016-04-15 17:45:50 +03:00
|
|
|
|
|
|
|
export default BaseValidator.create({
|
|
|
|
properties: ['email'],
|
|
|
|
|
|
|
|
email(model) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let email = model.email;
|
2016-04-15 17:45:50 +03:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (isBlank(email)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('email', 'Please enter an email.');
|
|
|
|
model.hasValidated.pushObject('email');
|
2016-04-15 17:45:50 +03:00
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isEmail(email)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('email', 'Invalid email.');
|
|
|
|
model.hasValidated.pushObject('email');
|
2016-04-15 17:45:50 +03:00
|
|
|
this.invalidate();
|
2017-11-16 15:47:56 +03:00
|
|
|
} else if (!validator.isLength(email, 0, 191)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('email', 'Email is too long');
|
|
|
|
model.hasValidated.pushObject('email');
|
2017-11-16 15:47:56 +03:00
|
|
|
this.invalidate();
|
2016-04-15 17:45:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|