Git Product home page Git Product logo

stymiee / email-validator Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 6.0 82 KB

The Email Validator library builds upon PHP's built in `filter_var($emailAddress, FILTER_VALIDATE_EMAIL);` by adding a default MX record check. It also offers additional validation against disposable email addresses, free email address providers, and a custom banned domain list.

Home Page: https://stymiee.dev

License: Apache License 2.0

PHP 100.00%
email email-validation php validation

email-validator's Introduction

Hi, I'm John Conde!

  • πŸ”­ I’m currently working at Dealer Inspire (Cars.com) as a Manager, Website Platform (Engineering)
  • πŸ˜„ Pronouns: He/Him/His

Trophies

Github Stats

Find me around the web:

Technology & Programming Social
stymiee.dev Untappd
John Conde .net LinkedIn
Stack Overflow @stymiee (Twitter)
Webmasters @SOHotQuestions (Twitter)
Github Last.fm
Packagist Instagram
Sitepoint (author) Pinterest
PHP Classes Steam
GOG

Read some of my blog articles

Hits since January 26, 2022

email-validator's People

Contributors

stymiee avatar terrypearson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

email-validator's Issues

related valid emails

If we provide valid email in $testEmailAddresses at the zero index in array like this:

$testEmailAddresses = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
];
It run perfect.

output :
Email is valid
Domain is used by free email providers
Domain is used by free email providers
Domain is used by free email providers
Domain is used by free email providers
Domain is banned
Domain is used by disposable email providers
Domain is used by disposable email providers
Domain is used by free email providers
Domain is used by disposable email providers
Domain is used by disposable email providers
Domain is used by disposable email providers

But if want to put valid emails in between two other types of emails
(change the position of valid emails in array $testEmailAddresses).
Then it give wrong output.
$testEmailAddresses = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
];

output: Domain is banned
Domain is banned
Domain is used by free email providers
Domain is used by free email providers
Domain is used by free email providers
Domain is used by free email providers
Domain is banned
Domain is used by disposable email providers
Domain is used by disposable email providers
Domain is used by free email providers
Domain is used by disposable email providers
Domain is used by disposable email providers
Domain is used by disposable email providers

Static variables prevents running validation with different configuration

Static variables are persisted during script execution, therefore it is not possible to validate several emails using different configuration.
The static $disposableEmailListProviders; in DisposableEmailValidator.php and static $freeEmailListProviders; in FreeEmailValidator.php are set on first class initialization and it is not possible to change them. These variables should be replaces with properties on the class e.g. private ?array $freeEmailListProviders = null;
remove_static_variables.patch.txt

Use case: there are two email fields one for personal and another for work email. Personal email has one set of free email providers while work email has different set.

$freeListSet = [
  'yandex.com', 
  'yandex.ru'
// ....
];

$personalEmailValidator = new EmailValidator([
  'checkMxRecords' => false,
  'checkBannedListedEmail' => false.
  'checkDisposableEmail' => true,
  'checkFreeEmail' => true,
  'bannedList' => [],
  'disposableList' => [],
  'freeList' => $freeListSet,
  'LocalDisposableOnly' => false,
  'LocalFreeOnly' => true,
]);

$workFreeListSet = ['gmail.com', ...$freeListSet];
$workEmailValidator = new EmailValidator([
  'checkMxRecords' => false,
  'checkBannedListedEmail' => false.
  'checkDisposableEmail' => true,
  'checkFreeEmail' => true,
  'bannedList' => [],
  'disposableList' => [],
  'freeList' => $workFreeListSet,
  'LocalDisposableOnly' => false,
  'LocalFreeOnly' => true,
]);

var_dump($personalEmailValidator->validate('[email protected]')); // true - ok
var_dump($workEmailValidator->validate('[email protected]')); // true - should be false as gmail.com is included in freeList

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.