Last active
November 11, 2015 18:51
-
-
Save DevotionGeo/4744cfcd3700c2ac93fb to your computer and use it in GitHub Desktop.
Custom validation rule in CodeIgniter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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