-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
is-email.js
34 lines (27 loc) · 862 Bytes
/
is-email.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Is Email
*
* @function sails.helpers.isEmail
* @param {String} email - The string to check if it looks like an email address.
*
* @returns {Boolean} True if the string appears to be an email address.
*/
module.exports = {
sync: true, // this is a synchronous helper
friendlyName: 'Is Email',
description: 'Does the provided string look like an email?',
inputs: {
email: {
type: 'string',
required: true
}
},
exits: {
success: {}
},
fn: (inputs, exits) => {
// eslint-disable-next-line no-useless-escape
const emailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/;
return exits.success(emailRegex.test(inputs.email));
}
};