Skip to content

Instantly share code, notes, and snippets.

@Committing
Last active January 6, 2016 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Committing/6c4cb2374f93971ecaea to your computer and use it in GitHub Desktop.
Save Committing/6c4cb2374f93971ecaea to your computer and use it in GitHub Desktop.
Test file to compare regex strings against different data.
<?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