PDA

View Full Version : php validation question



Abush
November 7th, 2006, 13:18
anyone know how to check an input in a form with php so that the email has a certain extention.
Ex. me@me.com is rejected and me@me.org is accepted. Basically I want it to make sure the .org is there before allowing it to continue.

Anyone? Krak?
Thanks!

krakjoe
November 7th, 2006, 13:53
of course....


<?
function check_ext($email)
{
if (!preg_match("/\.org$/", $email))
{
return false;
}
else {
return true;
}
}

if (!$_POST) {
echo "<form action='' method=\"post\">";
echo "<input type=\"text\" name=\"email\">";
echo "<input type=\"submit\" value=\"check\">";
}
else {
if (!check_ext($_POST['email']))
{
die("No match....your error message");
}
else{
echo "Accepted";
// continue
}
}
?>


You just need the function

Abush
November 7th, 2006, 16:11
Works beautifully ofcourse. Thank you sir!