CodeIgniter Forums
Adding an extra feature to CI form_validation class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Adding an extra feature to CI form_validation class (/showthread.php?tid=51183)



Adding an extra feature to CI form_validation class - El Forum - 04-24-2012

[eluser]satej[/eluser]
I usually come across name checks having the following requirement:-

1 - allowed characters are alphabets and spaces
2 - min-length -> 6

We come across numerous such situations for which we do not have any method in the form_validation class. So we have to provide callbacks to check for validity inside which we check against regular expressions.

It would be very handy if we could have a method like the one below which would enable us to check for regular expressions without writing callbacks each time we need such a method which is not present in the form_validation class.

Code:
/**
* Reg Exp
*
* @access public
* @param string
* @param value
* @return bool
*/
public function reg_exp($str, $val)
{
     if (preg_match("$val", $str))
     {
         return TRUE;
     }

     return FALSE;
}