Page 1 of 1

express problem

Posted: Tue Sep 18, 2007 11:12 am
by itsmani1
i want to check if the $var has minimum 5 characters and they are all of a-zA-Z0-9 and started with a-z but its not working.

here is my code:
any help

Code: Select all

$regex="/^[a-zA-Z]([a-zA-Z0-9]*){5,26}$/";
$var = 'a';
if(preg_match($regex,$var))
{
	echo "Hello";
}else
{
	echo "yall";
}
thank you

Posted: Tue Sep 18, 2007 11:17 am
by VladSun
Remove the * symbol from the pattern and check for range {4,26}

Re: express problem

Posted: Wed Sep 19, 2007 4:37 am
by GeertDD
itsmani1 wrote:i want to check if the $var has minimum 5 characters and they are all of a-zA-Z0-9 and started with a-z but its not working.

Code: Select all

preg_match('/^[a-z][a-zA-Z0-9]{4,}$/D', $var);

/D modifier

Posted: Sat Oct 20, 2007 4:01 am
by regexpert
What does /D modifier do?

Posted: Sat Oct 20, 2007 4:18 am
by Kieran Huggins