Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Wed Sep 26, 2007 1:02 pm
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
GeertDD
Forum Contributor
Posts: 274 Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium
Post
by GeertDD » Wed Sep 26, 2007 1:17 pm
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';
regexpert
Forum Newbie
Posts: 7 Joined: Sat Oct 20, 2007 3:41 am
Post
by regexpert » Sat Oct 20, 2007 3:47 am
you can add \s into the expression for space.
Code: Select all
$regex = '/^[-a-z0-9_.;:\s]{5,50}$/i';
GeertDD
Forum Contributor
Posts: 274 Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium
Post
by GeertDD » Sun Oct 21, 2007 9:06 am
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.