View Full Version : Regular expression

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,

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


Philip M
05-18-2007, 05:03 PM



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.