开发者

Zend_Filter and Zend_Validate for names with apostrophes

开发者 https://www.devze.com 2023-02-17 14:11 出处:网络
Hey guys, quick question, just trying to filter a user\'s first and last name via Zend_Filter, but some users could obviously be irish or something else.Does anyone have a filter and开发者_StackOverfl

Hey guys, quick question, just trying to filter a user's first and last name via Zend_Filter, but some users could obviously be irish or something else. Does anyone have a filter and开发者_StackOverflow社区 validate extension for this? Thx for your time guys.


You will have to implement a Regex Validator, with something like

 \w+[']?\w+

as the regex, depending on the placement/count of apostrophes

If you are not using Zend Form, This is a way to do it.

         $data = $this->getRequest()->getPost();

            //Filters Apply first before Validators.
            $filterRules = array();  


            //Validators are applied after Filtering.
            $validatorRules = array( 
                   'first_name' => array( 
                          new Zend_Validate_Regex('/\w+[']?\w+/'), 
                         'presence' => 'required', 
                         'allowEmpty' => false, 
                         'messages' => 'Blah Blah ));

   $input = new Zend_Filter_Input($filterRules, $validatorRules, $data);

Syntax may be off, and regex may not be to spec, but im sure you can figure out a regex.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号