Displaying characters that cause a validator to fail

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
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.
 
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)
 
Back
Top