* Phpu <[EMAIL PROTECTED]>:
> I have this function
>
> function validate_name($name) {
>
> if(ereg("^[a-zA-Z0-9_]{2,30}$", $name)) {
>
> return true;
>
> } else {
>
> return false;
>
> }
>
> }
>
> If i enter a name like John for exemple everything is ok but if i enter =
> John Doe the function return false.
You need to add a space to your character class:
if (ereg("^[a-zA-Z0-9_ ]{2,30}$", $name)) {
return true;
}
However, note also: pattern matching such as this is faster and more
flexible if you use the preg_* functions instead of the ereg_*
functions:
if (preg_match('/^[a-z0-9_ ]{2,30}$/i', $name)) {
return true;
}
will perform faster, and gives you case insensitivity with the 'i'
switch following the regexp.
--
Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php