467,894 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Displaying characters that cause a validator to fail

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.

Nov 18 '05 #1
  • viewed: 1135
Share:
1 Reply
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: PL****@PeterBlum.com

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3582C9.E135%sb***@niaid.nih.gov...
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.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by Brian | last post: by
9 posts views Thread by Safalra | last post: by
9 posts views Thread by Eric Lindsay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.