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/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Adding an extra feature to CI form_validation class (/thread-51183.html)



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;
}