Welcome Guest, Not a member yet? Register   Sign In
Validation rule for UNIQUE and NULL fields
#1
Question 

Is there some validation rule that will check for unique non-null values?

MySQL allows an index to be UNIQUE, but still allow multiple such columns to be NULL. I.e. it only applies the UNIQUE constraint if the column has a non-NULL value.

Does the same exist in CI validation rules?

-joho
Reply
#2

PHP Code:
if (!is_null($data['foo'])){
    $validation->setRules($foo_uniq_rule);

Reply
#3
Question 

Sorry, not sure I follow?

-joho
Reply
#4

You have these 2 Rules by default,

PHP Code:
is_not_unique
is_unique 

If that does not work for you than you will need to create your own Custom Rule.
What did you Try? What did you Get? What did you Expect?

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

Fair enough. But shouldn't is_unique handle this in the same way the database handles it? I guess that's my point.

-joho
Reply




Theme © iAndrew 2016 - Forum software by © MyBB