RegularExpressionValidator help

  • Thread starter Thread starter Mark Dengler
  • Start date Start date
M

Mark Dengler

I'm hoping this is simple. All I want to do is to make sure that a /
(slash) is not entered into a text box. here are some of my failed
attempts:

ValidationExpression="\w[^\/]"
ValidationExpression="\w[^/]"
ValidationExpression="^/"
ValidationExpression="[^/]"
ValidationExpression="w[^/]"

... and many more variations. please help!
 
Mark said:
.. and many more variations. please help!

if (!Regex.IsMatch("Is this string / valid?", "/"))
{
// You have a valid string, process it.
}

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Hi Mark,

You would have to make sure to include everything except the slash ... eg
....

ValidationExpression = "^[\w\s\d]*$"

.... add other things between the [] that you want to match. otherwise, go
with Frank's !Match solution

Alex Papadimoulis
 
Frank,

I'm leaning towards your solution because I'm able to specify the single
item that is not valid as opposed to everything that is. Does this
solution apply to server processing only or may I implement this on the
client?
 
You could use this one:

[^/]*

The "[^/]" syntax means "any character except for /". The "*" just means
"zero or more". You had the right idea in your fourth expression, but it
would only match if there were just a single character input. Adding the
"*" allows any size input (including zero-length) as long as there is no
slash.


Brian Davis
www.knowdotnet.com
 
Back
Top