...

View Full Version : Regular expression



prajwala
05-18-2007, 01:53 PM
I want regular expression which allows only alphanumeric values including -,_,/,\
all other special characters are not allowed.

Thanks in advance,
Prajwala

shyam
05-18-2007, 03:03 PM
try this

/[a-z0-9_/\-]+/i

Philip M
05-18-2007, 05:03 PM
/^[a-z0-9_\/\\\-]+$/i

or

/^[\w\/\\\-]+$/

The \ and / characters must be escaped with a \ to cause them to be interpreted as literals. I usually escape the hyphen - as well.
\w is equivalent to a-zA-Z0-9_

Note the ^ and $ characters - these define the start and end of the string to be tested. If they are not included then anything containing (one or more of) the permitted characters (something like ab&c or xyz%) will return true.

What is wanted is to permit a-Z0-9_\/- and nothing but.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum