Re: How to validate a name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 10, 2006 at 08:12:42AM +0000, Jony dos Santos Kostetzer wrote:
> Hmmm.. it's really difficult to deal with non-utf8 characters. I was read that 
> using setlocale() and [[:alpha:]] we avoid this problem, but I dont know.
> 
> Man, you forgot to escape some special characters and include "é" in your 
> regular expression. Use it:
> 
> preg_match("/^[^0-9][A-Za-z0-9\_\. !?\,~?`\^áãàâÁÃÀÂéêÊíÍúÚóÓõÕçÇ]{10,45}$/i",  
> "Coração de Leão no Café");

AFAIR these special characters lose their special meaning within a
character class (apart of the '-'). But if you put the dash at a
position where it can't be misinterpreted as range, even this works
without escaping.

The following returns OK.

<?php
$pattern = "/^[^0-9][a-zA-Z0-9-_. !?,~?`^áãàâÁÃÀÂéêÊíÍúÚóÓõÕçÇ-]{10,45}$/i";
$subject = "Coração de Leão no Café -_,.^";

if (preg_match($pattern, $subject)) {
  echo 'OK';
} else {
    echo '!OK';
}
?>

Feel free to emend this.

Regards,
Martin


PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux