|
Posted by Toby Inkster on 12/22/05 01:37
Dima Gofman wrote:
> a field is called "email" so it should be *@*.* and so on
<?php
function checkErr ($field, $regexp, $err)
{
if (!preg_match($regexp, $_REQUEST[$field]))
return "$err\n";
return '';
}
$errors = checkErr('email', '/.*\@.*\..*/', 'Invalid e-mail')
. checkErr('age', '/^[0-9]+$/', 'Invalid age')
. checkErr('name', '/[A-Za-z]+\s+[A-Za-z]+/', 'Please enter your full name');
if ($errors == '') print "OK!";
else
{
$E = explode("\n", $errors);
print "<p>Errors occurred:</p>\n";
print "<ul>\n";
foreach ($E as $e)
if ($e!='')
print "<li>$e\n";
print "</ul>\n";
}
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|