Hi Max and Grigri,
I've retested some solutions to validate with a custom regex, but no
success!
It seems the problem is due to "utf-8", because in a "iso-8859-1"
context, it seems to work...
My environment:
Cake 1.2.x.x nightly builds
PHP 5.2.5
MySQL 5.0.45
Apache 2
I've setted my LOCALE in bootstrap.php like that:
$locale = 'fr_FR.UTF-8';
if (env('REMOTE_ADDR') === '127.0.0.1' ||
(isset($_SERVER['HTTP_USER_AGENT']) && strpos('Win',
$_SERVER['HTTP_USER_AGENT']) !== false))
{
$locale = 'fra';
}
setlocale(LC_ALL, $locale);
And in my Model, I put this validation criteria:
public $validate = array(
'prenom' => array(
'alphabet' =>
array(
'rule' => array('custom', '/^[[:alpha:]]+$/'),
'message' => 'Caractères interdits'
)
)
)
And another test with:
public $validate = array(
'prenom' => array(
'alphabet' =>
array(
'rule' => array('custom', '/^\w+$/'),
'message' => 'Caractères interdits'
)
)
)
And another again:
public $validate = array(
'prenom' => array(
'alphabet' =>
array(
'rule' => array('custom', '/^[a-z]+$/i'),
'message' => 'Caractères interdits'
)
)
)
For all this pattern, if I put accented chars in my form, the
validation allways fails!
I've tested under Windows and Linux, with and without the LOCALE
There is only one case which works partially:
public $validate = array(
'prenom' => array(
'alphabet' =>
array(
'rule' => array('custom', '/^[[:alpha:]]/'),
'message' => 'Caractères interdits'
)
)
In this case, if I put an accented chars at the first place, the
validation is OK ?! But if I put a symbol at the second place, the
validation is OK too ?!
Maybe my regex patterns are not well-formated?
Maybe my combination with "setlocale" is not good?
Actually, it's a really problem for non-english lexical...
On 9 avr, 07:53, Max Romantschuk <[EMAIL PROTECTED]> wrote:
> On Apr 8, 3:04 pm, grigri <[EMAIL PROTECTED]> wrote:
>
> > For a locale-based solution, has anyone tried just using the \w
> > metachar, as in : `/^\w+$/` ?
>
> > Does this work?
>
> From what I could tell in PCRE's docs, how PCRE behaves is dependent
> on how it is compiled. At least the i-modifier is, according to the
> docs, do I'd assume the \w character class is as well. I wanted a
> solution that would be as immune as possible to installation dependent
> things like this. \w is the correct solution in theory, but I can't
> have my apps breaking because PRCE behaves a little bit differently in
> Linux distro X... :)
>
> .max
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---