Required Field Validator

S

Sparky Arbuckle

<asp:RequiredFieldValidator
id="rfvMenuSearch"
ControlToValidate="tbSearch"
Display="static"
ErrorMessage="Enter Search String"
runat="SERVER" />

How can I add an Expression Validator to this to cancel out all
searches for "` ! # ^ ( ) < > /", etc. . . Any insight on if a
validator is more efficient than a CleanData Function?

The only other way that I'm thinking it could be done is with Classic
ASP:

IF tbSearch.text = "^" OR . . . Thanks for any possible help.
 
W

Wilco Bauwer

You could try to use a RegularExpressionValidator instead:

<asp:Regu..... ValidationExpression="^[^!#^()<>/]+$" />

This should match 1 or more characters which are none of the chars you
described.

You could also use a CustomValidator, handle its ServerValidate event
and check if the index of any (String.IndexOfAny) of the chars you
described is > -1. If that's the case, the expression is invalid, so
you can set the arguments object's IsValid property to false.

HTH.
 

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