Skip to content

Instantly share code, notes, and snippets.

@DevotionGeo
Last active November 11, 2015 18:51
Show Gist options
  • Save DevotionGeo/4744cfcd3700c2ac93fb to your computer and use it in GitHub Desktop.
Save DevotionGeo/4744cfcd3700c2ac93fb to your computer and use it in GitHub Desktop.
Custom validation rule in CodeIgniter
<?php
class Something extends CI_Controller {
# some code
/**
* Full Name Check, custom validation rule
* How to use? : $this->form_validation->set_rules('fullName', 'Full Name', 'required|callback_fullname_check');
*/
public function fullname_check($str) {
if (! preg_match("/^([a-z0-9 ])+$/i", $str)) {
$this->form_validation->set_message('fullname_check', 'The %s field can only be alpha numeric');
return FALSE;
} else {
return TRUE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment