regex question

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

 



I am writing some regex on a php form to validate input and have come up 
with this, for example -

if (empty($first) || !eregi("^[A-Za-z]+[- ]?[A-Za-z]+$", $first))

for checking a persons name. This allows a single name, or a hyphenated 
double name, or a non-hyphenated double name, and it works. My question is 
this - why is the third set followed by a '+' optional? I thought the + 
meant the preceding group is present 1 or more times. The ? means the 
preceding group is present 0 or more times. Why is it that when I put a ? 
in the place of the + after the last ] 

if (empty($first) || !eregi("^[A-Za-z]+[- ]?[A-Za-z]?$", $first))

the regex is broken?

Regards,
Chip

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux