FILTER_VALIDATE_EMAIL.js

Email validation compatible with PHP's filter_var($value, FILTER_VALIDATE_EMAIL)
v2 ships as a single ES module. Breaking changes from v1:
- ESM package — there is no separate CommonJS build.
importworks everywhere;require()works on Node.js >= 22.12 via nativerequire(ESM).- Node.js >= 22 required.
- Only the package root is exported; deep imports (e.g.
filter-validate-email/es/...) are no longer available.- In the browser, load it as an ES module from a CDN (
<script type="module">, see below); there is no bundled browser global / UMD / IIFE build.If you need a real CommonJS build, a browser global, or older runtimes, stay on v1.
Installing
NPM
npm install filter-validate-email
CDN
Load it as an ES module from any npm CDN:
<script type="module">
import validateEmail from 'https://esm.sh/filter-validate-email';
validateEmail('...'); // true / false
</script>
jsDelivr (https://cdn.jsdelivr.net/npm/filter-validate-email/+esm) and unpkg (https://unpkg.com/filter-validate-email?module) work too.
It is strongly recommended that you pin a fixed version, e.g. https://esm.sh/filter-validate-email@2.0.0.
Usage
Validate Unicode Email (default)
PHP
<?php
$value = '...';
$result = (bool)filter_var($value, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE);
JavaScript
import validateEmail from 'filter-validate-email';
const value = '...';
const result = validateEmail(value);
Validate Ascii Email
PHP
<?php
$value = '...';
$result = (bool)filter_var($value, FILTER_VALIDATE_EMAIL);
JavaScript
import validateEmail from 'filter-validate-email';
const value = '...';
const result = validateEmail(value, false);
Appendix
- Pure HTML Version:
mpyw/FILTER_VALIDATE_EMAIL.html