Welcome Guest, Not a member yet? Register   Sign In
Problem with valid_email return true for invalid email address
#1

Hello,

I'm new to CI and just setup and working on the sign up form, but some how the valid_email rule in form validation is not working. I have tried the function valid_email() too and it's still not working. How come this email "a!b#c$e%g^h&j*[email protected]" can pass the validation?
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends CI_Controller
{
    public function 
index()
    {
        
$this->load->helper('email');

        if(
valid_email('a!b#c$e%g^h&j*[email protected]'))
        {
            echo 
'valid email';
        }
        else
        {
            echo 
'invalid email';
        }
        
$this->load->view('welcome_message');
    }



This code is displaying "valid email". Did I miss something? Please help.
Reply
#2

(This post was last modified: 03-17-2018, 01:26 PM by jreklund.)

Because it's valid (and don't know that gmail have restrictions):
https://en.wikipedia.org/wiki/Email_address#Examples
Reply
#3

So if I want to reject that email, then I guess I have to create my own rules.
Thanks jreklund.
Reply
#4

You should be using the PHP Filters.

PHP Code:
$email "[email protected]";

if (
filter_var($emailFILTER_VALIDATE_EMAIL)) {
 
 echo("$email is a valid email address");
} else {
 
 echo("$email is not a valid email address");

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 03-18-2018, 05:30 AM by jreklund.)

(03-17-2018, 03:16 PM)zjonsnowz Wrote: So if I want to reject that email, then I guess I have to create my own rules.
Thanks  jreklund.

That's correct. According to the standard it's valid, but I haven't seen any human include those signs... So you can also check for symbols and deny those e-email addresses.

@InsiteFX: That's exactly what that function does.
Reply
#6

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email address");
} else {
echo("$email is not a valid email address");
}
Reply
#7

@pooja7r

Why did you post and repeat something that I had already posted?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB