|
| 1 | +'use strict'; |
| 2 | + |
1 | 3 | /** |
2 | 4 | * Validation for email Input Plugin |
3 | 5 | * |
4 | | - * @param {Object} input - inputs in this plugin's instance and their values as {String} |
5 | | - * @param {Object} input.target - the triggering input's name and value as {String} |
6 | | - * @param {String} input.target.name - the triggering input's name |
7 | | - * @param {String|Bool} input.target.value - the triggering input's value |
8 | | - * @param {Object} input.all - all inputs in this plugin's instance |
9 | | - * @param {String|Bool} input.all.email - value of input email |
10 | | - * @param {Object} [settings] - settings for this input plugin instance |
11 | | - * @param {Object} [settings.target] - the triggering input's settings as an {Object} |
12 | | - * @param {Object} [settings.all] - all settings in this plugin instance as an {Object} |
13 | | - * @param {Object} [settings.all.email] - settings of input email {Object} |
| 6 | + * @param {object} input - inputs in this plugin's instance and their values as {string} |
| 7 | + * @param {object} input.target - the triggering input's name and value as {string} |
| 8 | + * @param {string} input.target.name - the triggering input's name |
| 9 | + * @param {string|bool} input.target.value - the triggering input's value |
| 10 | + * @param {object} input.all - all inputs in this plugin's instance |
| 11 | + * @param {string|bool} input.all.email - value of input email |
14 | 12 | * |
15 | | - * @returns {Bool|String} true or a string with the text describing the error |
| 13 | + * @returns {bool|string} true or a string with the text describing the error |
16 | 14 | * |
17 | 15 | * @module emailValidation |
18 | 16 | */ |
19 | | -module.exports = function emailValidation(input, settings) { |
20 | | - 'use strict'; |
21 | | - let domains; |
22 | 17 |
|
23 | | - domains = settings.target.domains || ['foo.com', 'bar.com', 'baz.com']; |
24 | | - if (!Array.isArray(domains)) { |
25 | | - domains = [String(domains)]; |
26 | | - } |
| 18 | +const isEmail = require('validator/lib/isEmail'); |
27 | 19 |
|
28 | | - if (!settings.target.regex.test(input.target.value)) { |
| 20 | +module.exports = function emailValidation(input) { |
| 21 | + if (!isEmail(input.target.value)) { |
29 | 22 | return 'Not a valid e-mail address.'; |
30 | 23 | } |
31 | 24 |
|
32 | | - if (!domains.some(domain => (input.target.value.indexOf(domain, input.target.value.length - domain.length) !== -1))) { |
33 | | - return `Email must be within the following domains: ${domains.toString()}`; |
34 | | - } |
35 | | - |
36 | 25 | return true; |
37 | 26 | }; |
0 commit comments