Page 1 of 1

regex for this ??

Posted: Tue Jun 05, 2007 10:53 pm
by PHPycho
Hello forums!!
I would like to know the regex for the following:
input text can contain
alphanumeric characters along with underscore and space
for example: "this is user_name"
i used the following:

Code: Select all

/^[a-zA-Z0-9 _]+$/
this works but not perfectly because when the only space bar is pressed it takes the value, i want to prevent this, space should be @ the beginning, what will be the regex for this ?
Thanks in advance to all of you [/quote]

Posted: Wed Jun 06, 2007 1:00 am
by PHPycho
I found this one .......

Code: Select all

/^[a-z0-9_][a-z0-9_ ]*$/i
any other alternatives
thanks a lot

Posted: Wed Jun 06, 2007 3:43 am
by Oren

Code: Select all

/^[a-z0-9 _]+$/iD

Posted: Wed Jun 06, 2007 6:43 am
by superdezign
And.. You'll probably want to give some sort of length specification.

Code: Select all

/^[a-z0-9_]{6,18}$/i

Descriptive subjects

Posted: Wed Jun 06, 2007 7:41 am
by feyd
Please update the title PHPycho.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.