<?php
$ypostcode = stripslashes($_REQUEST[you]);
$yourpostcode = htmlspecialchars($ypostcode);
if(!ereg('^[A-Za-z]{1,2}[0-9]{1,2}[[:space:]]{1,}[0-9][A-Za-z]{2}$',$ypostcode)){
$pcStat=0;
}
else{
$pcStat=1;
}
$yemail = stripslashes($_REQUEST[email]);
$youremail = htmlspecialchars($yemail);
if(!ereg('^[-A-Za-z0-9._]+@([-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$',$yemail)){
$emStat=0;
}
else{
$emStat=1;
}
?>
<html>
<head>
<title>This is an RegExpr demo</title>
</head>
<body bgcolor=#FFFF00>
<h1>Regular expressions</h1>
<table>
<form>
<tr><td>Please enter your postcode <td><input name = you value="<?= $yourpostcode ?>">
<tr><td>Please enter your email <td><input name = email value="<?= $youremail ?>">
<tr><td><input type=submit>
</form>
</table>
<hr>
<?
if ($yourpostcode && $pcStat){
print "Your post code is valid: $yourpostcode";
}
if ($yourpostcode && !$pcStat){
print "Your post code is not valid : $yourpostcode";
}
print "<p>\n";
if ($youremail && $emStat){
print "Your email address is valid: $youremail";
}
if ($youremail && !$emStat){
print "Your email address is not valid : $youremail";
}
?>
</body>
</html>
--
PeterJones - 08 Nov 2006