FILTER_VALIDATE_EMAIL.js
Email validation compatible with PHP's filter_var($value, FILTER_VALIDATE_EMAIL)
Installing
NPM
npm install filter-validate-email
CDN
<script src="https://unpkg.com/filter-validate-email@latest/dist/filter-validate-email.min.js"></script>
It is strongly recommended that you replace latest
with a fixed version.
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