Displaying characters that cause a validator to fail

S

Stephan Bour

Hi,
I have a regular expression validator that checks a text box string:

<asp:RegularExpressionValidator id="SeqFormat" runat="server"
Display="Static" ErrorMessage="Your sequence contains illegal characters"
ControlToValidate="Sequence"
ValidationExpression="^[AGTCagtc5678\n\s]{1,}$">

I'd like to provide the user with a listing of the illegal characters that
triggered a failure of the validator. Do you know how to capture the illegal
characters and display them in a label?
Thanks,
Stephan.
 
P

Peter Blum

Hi Stephan,

This may be a much bigger task than its worth. I have a feeling that
creating an error message telling users what they can type will be far
easier than writing this validator. (FYI: I am the author of "Professional
Validation And More", a replacement to Microsoft's validators that is
designed to overcome its many limitations. In this case, even I haven't
tackled this thorny issue.)

This is possible if you basically wrote your own validator using their
CustomValidator or subclassing from BaseValidator. Issues you face:
1. While you could still use a regular expression to detect errors, it
wouldn't tell you the invalid characters. You'd still have to loop through
the string and extract unique characters that were illegal.
2. Microsoft's validators were designed with a fixed error message property.
You'd have to update the ErrorMessage property while preserving its original
value. This is especially problematic on the client-side. You would build
your error message string and assign it to the InnerHTML property of the
<span> tag that represents the validator.
3. Remember to write it all both on the client and server sides.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top