express problem

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

express problem

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Remove the * symbol from the pattern and check for range {4,26}
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: express problem

Post 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);
regexpert
Forum Newbie
Posts: 7
Joined: Sat Oct 20, 2007 3:41 am

/D modifier

Post by regexpert »

What does /D modifier do?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Post Reply