Textbox validation in asp.net - remove spaces
I have a large group of text boxes that need to be checked. Used asp: RegularExpressionValidator..works great and everything but that ... because I execute so many of them ... they "hold" their space even if they don't appear. For example, I had 5 and then the word hello, if I call all 5 and they have a "#" error message it looks like this. "##### hello" .. if I didn't run any of them it would look like "hello" ... I want it to be if I didn't call any "hello" no matter how many "#hello" ... i thought about using a placeholder ... but not really sure how to constrain it .. also though about using javascript..but for some reason..javascript doesn't play well and throws an error every once ... so yeah ...any help on how to remove the whitespace and only show that the "error" would once have been helpful. All my error messages would be the same. Using visual studio 2010, asp and c # here's a validator
<asp:RegularExpressionValidator CssClass="failureNotification2" runat="server" ErrorMessage="*" ControlToValidate="txtOUT2SAT1" ValidationExpression="^[0-9]+\:[0-9][0-9]" />
edit-- I read that you can only make one control to validate ... I don't mind having 5 different validators. Just want them all to appear in one place ... or if there is an easy way to check all of them
source to share
-
If you don't want validators to "hold" their space, set your property
Display
toDynamic
:<asp:RegularExpressionValidator Display="Dynamic" ... />
-
If you want to display one common error message for all errors, use ValidationSummary , set its property
HeaderText
to the error message, and disable all error messages (i.e.ErrorMessage=""
on all validators).
source to share
What I can't figure out is that you need so many validators to fire all of the same textbox control at the same time. Can you post the validator check data? It is often enough to have
- required field validator
- regex validator
- sometimes custom validator for irregular logic
These validators are default and should be designed not to overlap in their validation range. If you want the expression in the text box to be formed in a certain way, you can do so by specifying it in the regular expression validator.
source to share