Page 1 of 1

what is giving me a parsing error?

Posted: Thu Sep 29, 2005 10:19 pm
by bruceg
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!

Posted: Thu Sep 29, 2005 10:22 pm
by feyd
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..

Posted: Fri Sep 30, 2005 1:43 am
by ruchit
feyd wrote:why do you have two nested eregi calls?
not a nested call, it seems to be pasting error :D

Posted: Fri Sep 30, 2005 1:50 am
by Jim_Bo
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

Posted: Fri Sep 30, 2005 3:45 am
by Jenk
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 :)

Posted: Fri Sep 30, 2005 1:24 pm
by Skara
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]$/