PHP – Email Validators

Email validators in PHP:

function validateEmail($email) {
    //$regex = '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
    $regex = '/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
    if (preg_match($regex, $email)) {
        //echo "'$email' is valid\n";
        return true;
    else {
        //echo "'$email' is invalid\n";
        return false;

function validateMultiEmail($emails) {
    $arrEmails = explode(",", $emails);
    foreach($arrEmails as $email) {
            return false;
    return true;
Posted in PHP

One thought on “PHP – Email Validators

  1. Hey nice function.

    There are much easier ways of doing this though depending on your browser support requirements. HTML5 provides a input type of “email” which works well for mobile devices also because it displays the “@” symbol on the keyboard when typing in that field.

    And there are also javascript libraries like Parsley JS that help with email validation among others.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s