RegularExpressionValidator help

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!
 
F

Frank Oquendo

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)
 
A

Alex Papadimoulis

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
 
M

Mark Dengler

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?
 
B

Brian Davis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top