#5145: Cake should have a alphanumeric+whitespace validation rule
----------------------------+-----------------------------------------------
    Reporter:  mryellow     |         Owner:          
        Type:  Enhancement  |        Status:  reopened
    Priority:  Low          |     Milestone:  1.2.x.x 
   Component:  Validation   |       Version:  RC3     
    Severity:  Normal       |    Resolution:          
    Keywords:               |   Php_version:  n/a     
Cake_version:               |  
----------------------------+-----------------------------------------------
Comment (by jperras):

 ''(Note: I have posted a very detailed response in the google-group, which
 is a more appropriate venue for this type of discourse:
 http://groups.google.com/group/cake-
 php/browse_thread/thread/5da14ef82b2c257e )''[[BR]][[BR]]


 There are many ways in which you can implement this feature yourself in
 CakePHP. Here's one approach:

 {{{
 // in either your app_model.php or a model class
     public function alnumWhitelist($data, $whitelist = array()) {
         $data = array_values($data);
         $check = $data[0];
         $whitelist = implode($whitelist);
         $rule =
 "/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}{$whitelist}]+$/mu";

         return preg_match($rule, $check);
     }


 // in your model validation rules
 // Note that some special characters need to be properly escaped.
  public $validate = array(
         'name' => array(
             'rule' => array('alnumWhitelist', array('\s', '\-', "\'",
 '\"')),
             'allowEmpty' => false
         ),
     );

 }}}

 You can place the custom validation rule in a model, or make it available
 on an application-level by putting it in your app_model. If you want to
 get fancy you could also wrap up the validation rule in a behavior, add
 test cases and put the whole lot in a plugin, which would make the whole
 thing portable, re-usable and application independent.[[BR]][[BR]]

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5145#comment:14>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to