Re: Help on custom validator using preg_match
Sorry, you are right, I misspelt it.
Here is the way I call my rule
'rule' => array('latin9AlphaNumeric', false, array( '-', '\'' ) )
Results in the regexp "/[^A-Z¦¨´¸-\']/i".
The validation method is as follows:-
static function latin9AlphaNumeric($data, $digits, $chars = array( ) )
{
// $data should contain a single element, the field being
validated.
$target = array_pop($data);
// Compile the regexp.
$regex = '/[^A-Z' . $GLOBALS['LATIN_9_EXTCHARS_STRING']; //
LATIN_9_EXTCHARS_STRING defined in startup.php bootstrap
if ($digits === true) $regex .= '\\d';
foreach ($chars as $char) {
$regex .= $char;
}
$regex .= ']/i';
// If preg_match returns 0 no offending chars were found, return
true.
// In any other case return false.
return preg_match($regex, $target) == 0 ? true : false;
}
still "d'ocy" will return a validation error ...
If I run 'rule' => array('latin9AlphaNumeric', false, array( '-') )
Results in the regexp "/[^A-Z¦¨´¸-]/i".
(without '\'' ) the validation rule works, thus "d-ocy" works.
I suspect that ' is a very, very "special" character that must be
handled with more care, the escape character is not enough ...
Your thoughts? I am really stuck and not a regexp expert :-(
--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cake-php?hl=.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home