开发者

Zend_Filter and Zend_Validate for names with apostrophes

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜