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.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.