custom validation in codeigniter using callback function is easy way to validate input field on form dynamically. We can add custom validation to any input field before insertion in DB. CodeIgniter provide all basic validation with its form_validation class like required, numeric, min_length, max_length, alpha, alpha_numeric etc.
But If we want to add our custom validation for any particular field (mainly for the checking username availability). we can use its callback technique.

Example :

Here $username is passed automatically to check_username function, we can use our custom rules over here to validate it.

Along with CodeIgniters basic validations you can use your custom conditions (like regular expressions) for a validation on any input field. you can also use regular expression to validate it in your way.