Page 1 of 1

Quick eregi syntax help

Posted: Mon Mar 10, 2003 4:39 pm
by virgil
Hi Php's :D

Im pulling my hair out on this, It should be easy but my syntax sucks.

I need to check that a string allows only numbers, letters and or spaces...

I tried a bunch of |\s and |\t stuff but I dont know what the hell Im doing.

Code: Select all

$namelength=strlen($name);
     if (eregi("її:alnum:]]{" . $namelength . "}", $name)){
         $d = TRUE;
    }else{
        $d = FALSE;
        $messageї] = "Please enter a valid name.";
How do I allow spaces or other characters anywhere in the string?

Any tweaking would be most appreciated.

Thaks a Mill :)

Virgil

Posted: Mon Mar 10, 2003 6:19 pm
by JPlush76

Code: Select all

<?php

$pattern = "^[a-z0-9 ]{1,}$";
								if (eregi($pattern, $field))
								{
										return true;
								}
								else
								{
														return false;
								}
?>

Posted: Mon Mar 10, 2003 6:24 pm
by lazy_yogi
function isvalid($name){
return preg_match('/^[\w\d\s]+$/', $name);
}


$name = "some name blah !";

if ( isvalid($name) ) echo "valid";
else echo "Please enter a valid name";

Posted: Mon Mar 10, 2003 8:01 pm
by virgil
I was so close, and yet so far...


Most Gracious Thanks

Virgil :D :D :D