Custom validation Rules in codeigniter ?

CodeIgniter Form Validation Library is Pretty Simple to Use and very powerful. We can define our own Custom Validation Rules in CodeIgniter in two different approaches.

1. By Using Callbacks.
2. By Extend CodeIgniter’s Form Validation library.

Custom validation Rules Using Callbacks

custom validation in CodeIgniter using callback function is an easy way to validate form fields. Follow the Steps,

1. define your custom rule with callback_ prefix,

2. Then add the method in the controller. This method needs to return either TRUE or FALSE

3. The Final Step, create a corresponding error Message to show on validation fail

Custom validation Rules By Extend CodeIgniter’s Form Validation library

Create a new PHP’s Class file named MY_Form_validation.php and put it in the application/libraries/ directory, and extend it with CodeIgniter’s validation library.

2. now add this to your validation rules

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
gopal venu
gopal venu
2 years ago

this is not working for me

arjun
2 years ago
Reply to  gopal venu

Are you getting any errors

arjun
2 years ago
Reply to  gopal venu

just verified, this one is working $this->form_validation->set_rules(’email_address’, ‘Email address’, ‘required|email_check’);

I dont have to time now check this, its only working with the combination of required rule

Himanshu Nishad
Himanshu Nishad
2 years ago

good this works fine after making my form validation in library.

Alfredo Galano Loyola
Alfredo Galano Loyola
2 years ago

You save my life, during a lot of time trying with callback and fail, now I try extending the library and work pretty good for me! Thanks a lot!

Parag Dhali
Parag Dhali
2 years ago

not working in CI v3 Showing ——–> Unable to access an error message corresponding to your field name email_id.(email_check)

Marcelo
Marcelo
2 months ago

Hello Arjun, how is it going?
Do you have a complete example about callback in CodeIgniter 3 to show us?
I mean with html, controller and MY Form_validation in a project.

Marcelo
Marcelo
2 months ago
Reply to  Arjun

Thank you Arjun.
This way is better to see whole example.

DMCA.com Protection Status
9
0
Would love your thoughts, please comment.x
()
x