PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bruceg
Forum Contributor
Posts: 174 Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:
Post
by bruceg » Thu Sep 29, 2005 10:19 pm
I get a parsing error within the following block. Trying to validate email input on a form. I am not sure the proper syntax with the if statments. I have currently:
Code: Select all
//Validating Email Address
if ($_POST['email'] != $_POST['email2']) { $email_err = "\n<span class='red'>e-mail address fields do not match!</span>"; }
elseif(!eregi("!eregi("^(.+)@(.+)\\.(.+)$",$_POST['email']))
{
$error_msg .= "<br />Your email appears to be invalid.";
$ok = "false";
}
there is also an additional if statement after the code I have posted, but I believe this part is what is gving me the error.
Someone please enlighten me!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Sep 29, 2005 10:22 pm
why do you have two nested eregi calls?
that's the error though.. as you may see the string of the first eregi is terminated by the nested eregi's string..
ruchit
Forum Commoner
Posts: 53 Joined: Mon Sep 26, 2005 6:03 am
Post
by ruchit » Fri Sep 30, 2005 1:43 am
feyd wrote: why do you have two nested eregi calls?
not a nested call, it seems to be pasting error
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Fri Sep 30, 2005 1:50 am
hi,
Why not just use something like:
Code: Select all
if (($_POST['email']) != ($_POST['email2'])) {
echo 'Email addresses dont match';
return;
}
if (!eregi("!eregi("^(.+)@(.+).(.+)$",$_POST['email'])) {
echo 'Please enter a valid email address';
return;
}
continue with script
hth
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Fri Sep 30, 2005 3:45 am
Hi,
I've used the following function in the past for email address validation:
Code: Select all
<?php
function emailCheck ($string) {
$string = preg_replace("/\r|\n/", "", $string);
if (preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9_\-.]+(\.[a-zA-Z0-9]{2,3})+$/", $string)) {
return $string;
}
else {
return false;
}
}
?>
It will also remove and line breaks, which is a common method for mail spoofing/spamming/hijacking.
HTH
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Fri Sep 30, 2005 1:24 pm
You forget the .museum extension, and an address cannot start with a _, -, or .. This is (I think) a fairly exact email regex:
Code: Select all
/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/