chelout/simple-email-validator

Simple Email Validator

v0.1 2020-09-11 07:00 UTC

This package is auto-updated.

Last update: 2024-11-11 17:15:31 UTC


README

Installation

You can install the package via composer:

composer require chelout/simple-email-validator

Usage

$validation = new EmailValidator([
    new RegexpRule(),
    new MxRule(),
]);
$validation->validate('user@example.com'); // boolean result
var_dump($validation->getErrors());

Custom rules

To create custom rule, you should implement Chelout\EmailValidator\Rules\RuleContract:

class FilterVarRule implements RuleContract
{
    public function isValid(string $email): bool
    {
        return ! (filter_var($email, FILTER_VALIDATE_EMAIL) === false);
    }

    public function getError(): string
    {
        return 'Filter Var Rule failed.';
    }
}