Welcome Guest, Not a member yet? Register   Sign In
Email validation
#1

[eluser]yorvik[/eluser]
Hello,

CI uses this for the form_validation of emails:

Code:
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;

But when I want to add this emailadres: [email protected], I always get an error of not valid email. How can I fix this.

Thanks in advance
#2

[eluser]Cristian Gilè[/eluser]
It works for me. Please, provide your code.

Cristian Gilè
#3

[eluser]yorvik[/eluser]
Code:
<?php
$email = mysql_real_escape_string($_POST['signup-email']);

if(!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)){
   echo "ERROR email adres";
}
else
{
    echo "good";
}
?>

I think it has something to do with this:

$email = mysql_real_escape_string($_POST['signup-email']);
#4

[eluser]Atharva[/eluser]
First, run the regex and then use
Code:
mysql_real_escape_string()
function. Also, are you really inserting that post value in db?

In fact, why you are not using CI's inbuilt class
Code:
if(!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)){
$data['signup-email'] = $this->input->post('signup-email');
$this->db->insert('table',data);
echo "ok";
}
else
{
//invalid email error
}
#5

[eluser]yorvik[/eluser]
OK thank you no I am not inserting the post value. I was testing this when I realised I don't need to use mysql_real_escape_string. Thanks anyway:p




Theme © iAndrew 2016 - Forum software by © MyBB