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 validate extension for this? Thx for your time guys.
Asked
Active
Viewed 606 times
1
-
I don't see a problem as long as you are consistently using UTF-8 as encoding. – Daff Mar 18 '11 at 20:51
-
3It's their name - why try to filter this at all? The dude that legally changed his name to contain a "2" won't enjoy the false negative this script would throw out. Just make sure the value isn't blank or all whitespace and proceed. – Peter Bailey Mar 18 '11 at 20:52
-
1I think the OP means validation in general. Of course he has to validate the user input and if there is no Zend_Validate validator that suits for names with uncommon signs like O'Hara then he needs to write a custom validator, which is, I think, what he's asking for. The validator which is normally used for that is 'Alnum' and I remember I've seen a way to add accepted chars, I just couldn't find anything about it in the manual now. – markus Mar 18 '11 at 21:47
-
Hey guys, I appreciate the responses. Yeah I'm mainly looking for a validator or an easy way to add an allowable character, otherwise i'll just write one myself. As for the filter, I was thinking just incase they misstyped, but yeah probably unnecessary anyway. Thx again guys. – blacktie24 Mar 18 '11 at 23:05
-
1The real question is what are the disallowed characters? :) IMO there ane no disallowed characters. You should only escape the name properly on output. – Tomáš Fejfar Mar 19 '11 at 11:54
1 Answers
2
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.

Bodman
- 7,938
- 3
- 29
- 34