Page 1 of 1

help with email validation

Posted: Sun Dec 10, 2006 11:08 pm
by darkfreaks
ok so i tried adding an email validation to my form

the actual function is in a file called func.php

so i included it in the php code then pasted this code. and it says undefined call to function?

Code: Select all

[syntax=php]include("functions.php");
$email = validateemail($_POST['email']);
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }
[/syntax][/quote]

Posted: Sun Dec 10, 2006 11:27 pm
by Sloth
Check if validateemail is in your functions.php or if your script is actually finding the functions.php

Maybe you can try replacing the include by a require statement and see if any errors pop up

Posted: Sun Dec 10, 2006 11:39 pm
by darkfreaks
the error i get is Fatal error: Call to undefined function: validateemail()

my function in func.php is :

Code: Select all

[syntax=php]//VALIDATE EMAIL
function validateemail($str) {
if (eregi("^[[]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $str) && strlen($str <= 255)) { return $str; }
else { return false; }
}
[/syntax]

Posted: Sun Dec 10, 2006 11:45 pm
by Sloth
try change

Code: Select all

include("functions.php"); 
$email = validateemail($_POST['email']); 
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }
to

Code: Select all

require("functions.php"); 
$email = validateemail($_POST['email']); 
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }
And see if it produces an error, if it does that means your functions.php file cannot be located (You might want to check up on file permissions too :))

Posted: Mon Dec 11, 2006 12:03 am
by darkfreaks
now its not giving me anything it just skips over the validation woiwdew' *bangs head on desk*

Posted: Mon Dec 11, 2006 12:18 am
by Sloth
maybe you could try replace the validateemail function with this

Code: Select all

function validate($email) {
preg_match_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]$/', $email, $match);
if (!empty($match[0][0]) && (strlen($email) <= 255))) {
return $match[0][0];
} else {
return false;
}