Created
August 8, 2013 10:12
-
-
Save PeeHaa/6183426 to your computer and use it in GitHub Desktop.
Emailaddress regex pattern tester
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 | |
if (isset($_POST['submit'])) { | |
$html = file_get_contents('http://fightingforalostcause.net/misc/2006/compare-email-regex.php'); | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($html); | |
//$results = $dom->getElementById('results'); | |
$xpath = new DOMXPath($dom); | |
$nodes = $xpath->query("//table[@id='results']/tr/td[1]"); | |
$addresses = [ | |
'valid' => [], | |
'invalid' => [], | |
]; | |
$type = 'valid'; | |
foreach ($nodes as $node) { | |
if ($node->textContent == 'These should be invalid') { | |
$type = 'invalid'; | |
continue; | |
} elseif ($node->textContent == 'These should be valid' || !trim($node->textContent)) { | |
continue; | |
} | |
$addresses[$type][] = $node->textContent; | |
} | |
echo '<h1>Valid emailaddresses</h1>'; | |
echo '<table>'; | |
foreach ($addresses['valid'] as $address) { | |
$passFail = (preg_match($_POST['pattern'], $address) === 1) ? 'PASS' : 'FAIL'; | |
echo ' <tr>'; | |
echo ' <td>' . $address . '</td>'; | |
echo ' <td>' . $passFail . '</td>'; | |
echo ' </tr>'; | |
} | |
echo '</table>'; | |
echo '<h1>Invalid emailaddresses</h1>'; | |
echo '<table>'; | |
foreach ($addresses['valid'] as $address) { | |
$passFail = (preg_match($_POST['pattern'], $address) === 0) ? 'PASS' : 'FAIL'; | |
echo ' <tr>'; | |
echo ' <td>' . $address . '</td>'; | |
echo ' <td>' . $passFail . '</td>'; | |
echo ' </tr>'; | |
} | |
echo '</table>'; | |
} | |
?> | |
<form action="" method="post"> | |
<input type="text" name="pattern"> | |
<input type="submit" name="submit" value="validate"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment