Custom form validation in Codeigniter

Hi Geeks,
Today i am sharing you the Custom form validation example in codeigniter. Suppose we have a custom requirement to validate the data with our own custom rules like email already exist in database, So for this type on need can be resolve only with custom callback functions .these are the following steps to create a custom validation for any form.
Step 1: Form Layout form.php in views

Now , We have 4 fields in this form –
first name,last name, email and password
for validate these fields codeigniter already provided rules in form_validation library:
Some of the rules are following listed:
valid_email,required,valid_email,valid_url,min_length[5]|max_length[12] etc.

But Now we need to detect that email already registered in Database ,So we need to create a callback function for validating the email already check in database.

Note:Codeigniter itself providing rule for ‘value already exists in database’ but here our purpose is to demonstrate the custom form validation in codeigniter thats why we are assuming that this need a custom form validation.
Step 2. Create a callback to match the field’s value in database

Step 3. Load Form validation library in controller’s Action or Constructor method as following:

Step 4. Now pass the array of validation rules for the form in add method of user controller as following:

Please comment here if you have any query regarding to this form validation snippet or not cleared anything.