Page 1 of 1

expression problem

Posted: Wed Sep 26, 2007 1:02 pm
by itsmani1
Here is my expression:

Code: Select all

$regex="/^[a-zA-Z0-9_\.\-\;\:]{5,50}$/";
It don't allow space, it works fine with "AhmedCenter" but don't with "Dizyn inc"
Please help me i want it work with "Dizyn inc" means it can allow spaces as well.

thank you

Posted: Wed Sep 26, 2007 1:17 pm
by GeertDD
Well, add a space inside the character class...

Code: Select all

$regex="/^[a-zA-Z0-9_\.\-\;\: ]{5,50}$/";
And then clean it up:

Code: Select all

$regex = '/^[-a-z0-9_.;: ]{5,50}$/i';

Space

Posted: Sat Oct 20, 2007 3:47 am
by regexpert
you can add \s into the expression for space.

Code: Select all

$regex = '/^[-a-z0-9_.;:\s]{5,50}$/i';

Re: Space

Posted: Sun Oct 21, 2007 9:06 am
by GeertDD
regexpert wrote:you can add \s into the expression for space.

Code: Select all

$regex = '/^[-a-z0-9_.;:\s]{5,50}$/i';
A space is what you get when you hit the space bar of your keyboard. The \s metacharacter includes spaces but other whitespace as well, e.g. tabs and newlines. I doubt itsmani1 wants to allow those as well.