Repository URL to install this package:
|
Version:
5.0.0 ▾
|
/**
* Is validating inputs for the MultiEmailSelect component.
* We need to allow domains and sub domains starting with a @ here as well
* @param {String} string
*/
export default function isEmailValidForWhitelist(string) {
const emailRE = new RegExp(
/^(.*)@((\[[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 emailRE.test((typeof string === 'string' && string) || '');
}
/**
* This regex matches text of the following forms:
* name <something>
* name (something)
* "name" <something> (other valid quote symbols: „"'‚)
* email@domain
*
*
* The regex is made out of the two following parts:
*
* (?:([^,;@]+?)\s<)?
* An optional name. It checks whether the string is preceded by some text that does not contain a comma, semicolon
* or @ symbol. The quotes are removed in a second step. If a name is present, the next string must be contained in angle
* brackets "<" and ">" or normal brackets "(" and ")".
*
* (?:([^\s<(,]+@[^\s,;)>]+)>?)
* Basically checks that the thing contains any characters that can be accepted.
* This excludes commas and semicolons. This allows invalid emails in the above format to be accepted
* into the input and later on will be flagged up as an invald entry.
*/
// eslint-disable-next-line no-useless-escape
const TEXT_WITH_NAME_REGEX = /(?:([^,;@]+?)\s[<|\(])?(?:([^\s<(,;)>]+)[>|\)]?)/g;
/**
* This one is the one the type="email" input uses internally, provided by MDN.
*/
const STRICT_EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
export { isEmailValidForWhitelist, TEXT_WITH_NAME_REGEX, STRICT_EMAIL_REGEX };