I need to validate the email address of my users. Unfortunately, making a validator that conforms to standards is hard.
Here is an example of a regex expression that tries to conform to the standard.
Is there a PHP library (preferably, open-source) that validates an email address?
The validateEmail() function above uses the filter_var() PHP function to validate an email address. If you pass the FILTER_VALIDATE_EMAIL option filter to it, filter_var() will validate the email address stored in $email from a syntactical point of view and return the filtered data on success, or false on failure.
Most email service providers (ESPs) provide email validation services. There are many free tools that also validate email addresses; ValidateEmailAddress, EmailValidator and Pabbly Email Verification are few of such examples.
Real time email verification lets you verify email addresses as they are typed in the signup form. Our REST API instantly checks if the address is valid and helps customers correct email typos. It also prevents disposable, invalid or shared addresses from getting into your list and lowering your mailing list quality.
Example. <? php $email = "[email protected]"; // Validate email if (filter_var($email, FILTER_VALIDATE_EMAIL)) { echo("$email is a valid email address"); } else{ echo("$email is not a valid email address"); } ?>
Have you looked at PHP's filter_ functions? They're not perfect, but they do a fairly decent job in my experience.
Example usage (returns boolean):
filter_var($someEmail, FILTER_VALIDATE_EMAIL);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With