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.
精彩评论