Welcome Guest, Not a member yet? Register   Sign In
Validation Rules: Valid email, but allow null?
#1

(This post was last modified: 05-19-2025, 02:08 PM by sevmusic.)

In my app I have 2 email address fields.

The first field is required because it's the main account.

The second field is optional.

Here are my rules currently.

PHP Code:
public $profile = [
    
'login_email' => ['label' => 'Login Email''rules' => 'required|valid_email'],
    
'login_email_2' => ['label' => '2nd Login Email''rules' => 'valid_email'
]; 

But when I leave the login_email_2 field blank it complains that it's not a valid email.

How can I ignore the valid email rule if the field is blank?

I think I solved my own problem with permit_empty

Is there a listing of all the codeigniter validation rules?

I didn't see them singled out in the docs.
Reply
#2

(This post was last modified: 05-19-2025, 09:31 PM by grimpirate.)

Rules for General Use.
Reply
#3

You can not have an email that is empty using that rule, you could check it an see if it has a value
in your code then set it to permit_empty and remove the valid_email one check it in your code.
What did you Try? What did you Get? What did you Expect?

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

(05-19-2025, 09:28 PM)grimpirate Wrote: Rules for General Use.
Thank you!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB