Last active
January 6, 2016 13:18
-
-
Save Committing/6c4cb2374f93971ecaea to your computer and use it in GitHub Desktop.
Test file to compare regex strings against different data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$regex = '/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'; | |
$show = 'emails'; | |
switch ($show) { | |
case 'emails': | |
//http://stackoverflow.com/questions/19220158/php-filter-validate-email-does-not-work-correctly | |
$test_against = array( | |
array('jack@ab-uk.com', true), | |
array('test@funnystuff11@hotmail.co.uk', false) | |
); | |
break; | |
} | |
foreach ($test_against as $var) { | |
$e = $var[0]; // Email | |
$f = $var[1]; // Flag | |
if (preg_match($regex, $e) == $f) { | |
if ($f === true) { | |
echo 'Success: Correct Email: ' . $f . ' - ' . $e . '<br />'; | |
} else { | |
echo 'Success: Incorrect email: ' . $f . ' - ' . $e . '<br />'; | |
} | |
} else { | |
echo 'FAILURE: Incorrect match: ' . $f . ' - ' . $e . '<br />'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment