Regular expression for matching email addresses
npm install email-regex> Regular expression for matching email addresses
Use it for finding email addresses or checking if something is email like.
You shouldn't use this for validating emails. Only for hinting to the user.
``sh`
npm install email-regex
`js
import emailRegex from 'email-regex';
// Contains an email address
emailRegex().test('unicorn sindresorhus@gmail.com');
//=> true
// Is an email address
emailRegex({exact: true}).test('sindresorhus@gmail.com');
//=> true
'unicorn sindresorhus@gmail.com cake john@doe.com rainbow'.match(emailRegex());
//=> ['sindresorhus@gmail.com', 'john@doe.com']
`
Returns a regex for matching email addresses.
#### options
Type: object
##### exact
Type: boolean\false
Default: (Matches any email address in a string)
Only match an exact string.
Useful with RegExp#test to check if a string is an email address.
##### allowSingleLabelDomain
Type: boolean\true
Default:
Allow emails with a domain that doesn't have a dot, such as user@localhost or user@internal.
##### allowAmpersandEntity
Type: boolean\false
Default:
Allow the ampersand HTML entity & to correspond to an ampersand &` in the email address.
If you run the regex against untrusted user input in a server context, you should give it a timeout. It's also a good idea to limit the input to a reasonable length.
I do not consider ReDoS a valid vulnerability for this package.