3

I have a large group of text box's that need to be validated..used the asp:RegularExpressionValidator ..works fine and all except that..because i'm performing so many of these...they "hold" their space even if they do not appear..like say i had 5 and then the word hello if i trigger all 5 and they have an error message "#", it would look like this.. "#####hello" ..if i didnt trigger any of them it would look like this " hello" ...i want it to be if i didnt trigger any "hello" any regardless of how many "#hello"...i've thought about using a placeholder..but not exactly sure how to limit it..also though about using javascript..but for some reason..javascript isnt playing nice and causes an error everytime...so yea.. any help on how to remove the whitespace and only show the "error" once would be helpful..all my error messages would be the same.. using visual studio 2010, asp and c# here is the validator

<asp:RegularExpressionValidator  CssClass="failureNotification2" runat="server" ErrorMessage="*" ControlToValidate="txtOUT2SAT1" ValidationExpression="^[0-9]+\:[0-9][0-9]"  />

edit-- i've read you can only do one control to validate...i dont mind having 5 different validators..just want them all to appear in one place..or if there is an easy way to check them all

2 Answers 2

3
  1. If you don't want validators to "hold" their space set their Display property to Dynamic:

    <asp:RegularExpressionValidator Display="Dynamic" ... />

  2. If you want to display a single generic error message for all errors, use a ValidationSummary control, set its HeaderText property to the error message and turn off all error messages (i.e. ErrorMessage="" on all validators).

Sign up to request clarification or add additional context in comments.

2 Comments

how would you do that? in the ControlToValidate ?
the dynamic part helps 2 problems actually..and works good enough for what i need..thank you..will look into the ValidationSummay as well
1

I cannot understand what you need so many validators for on one textbox control that all fire at the same time. Can you post what the validators check? Often it is enough having

  • a required field validator
  • a regular expression validator
  • sometimes a custom validator for irregular logic

These validators are by default and should be designed as not to overlap in their checking range. If you want the expression in the textbox formed in a certain way, you can do so by prescribing it in the regular expression validator.

2 Comments

its not for one textbox control..in that example..i would have 5 text boxes..one validator for one textbox
Ok, sorry, I misunderstood your question then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.