# email-regex

> Regular expression for matching email addresses

Latest version **6.1.0** (published 2025-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install email-regex
pnpm add email-regex
yarn add email-regex
bun add email-regex
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2025-08-17 |
| First published | 2014-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 149 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | email, address, regex, regexp, string, match, text, test, find, pattern, validate |

## Links

- npm: https://www.npmjs.com/package/email-regex
- Repository: https://github.com/sindresorhus/email-regex
- Homepage: https://github.com/sindresorhus/email-regex#readme
- Issues: https://github.com/sindresorhus/email-regex/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/email-regex

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 6.1.0 (latest) — 2025-08-17
- 6.0.0 — 2025-08-04
- 5.0.0 — 2021-05-03
- 4.0.0 — 2019-06-29
- 3.0.0 — 2018-05-27
- 2.0.0 — 2017-11-08
- 1.0.0 — 2014-09-07

## README

# 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.](https://davidcel.is/articles/stop-validating-email-addresses-with-regex) Only for hinting to the user.

## Install

```sh
npm install email-regex
```

## Usage

```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']
```

## API

### emailRegex(options?)

Returns a regex for matching email addresses.

#### options

Type: `object`

##### exact

Type: `boolean`\
Default: `false` *(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`\
Default: `true`

Allow emails with a domain that doesn't have a dot, such as `user@localhost` or `user@internal`.

##### allowAmpersandEntity

Type: `boolean`\
Default: `false`

Allow the ampersand HTML entity `&amp;` to correspond to an ampersand `&` in the email address.

## Important

If you run the regex against untrusted user input in a server context, you should [give it a timeout](https://github.com/sindresorhus/super-regex). It's also a good idea to limit the input to a reasonable length.

**I do not consider [ReDoS](https://blog.yossarian.net/2022/12/28/ReDoS-vulnerabilities-and-misaligned-incentives) a valid vulnerability for this package.**

---
_Source: https://npm.io/package/email-regex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
