[PHP] Validate Email Address Format

A quick snippet I use to validate email address format.

<?php

if (empty($argv[1]))
{
    echo 'usage: ' . $argv[0] . ' [email protected]' . PHP_EOL;
    exit (1);
}

array_shift($argv);

foreach ($argv as $key => $email) 
{
    echo (filter_var($email, FILTER_VALIDATE_EMAIL)) ? 'valid     ' : 'not valid '; 
    echo "($email)" . PHP_EOL;
}

E.g

cat members.csv | awk -F',' '{print $1}' | xargs -n50 validate_email.php

 

You may also like...

Leave a Reply

Your email address will not be published.