1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('./Validator');
|
7 |
|
8 | module.exports = class EmailValidator extends Base {
|
9 |
|
10 | constructor (config) {
|
11 | super({
|
12 | pattern: '^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$',
|
13 | maxLength: 128,
|
14 | ...config
|
15 | });
|
16 | }
|
17 |
|
18 | getMessage () {
|
19 | return this.createMessage(this.message, 'Invalid email');
|
20 | }
|
21 |
|
22 | validateValue (value) {
|
23 | if (typeof value !== 'string' || value.length > this.maxLength) {
|
24 | return this.getMessage();
|
25 | }
|
26 | if (!(new RegExp(this.pattern)).test(value)) {
|
27 | return this.getMessage();
|
28 | }
|
29 | }
|
30 | }; |
\ | No newline at end of file |