Quick eregi syntax help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Quick eregi syntax help

Post 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
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

Code: Select all

<?php

$pattern = "^[a-z0-9 ]{1,}$";
								if (eregi($pattern, $field))
								{
										return true;
								}
								else
								{
														return false;
								}
?>
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post 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";
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Post by virgil »

I was so close, and yet so far...


Most Gracious Thanks

Virgil :D :D :D
Post Reply