Eddy Whitaker
Eddy Whitaker

Reputation: 141

text box validation in asp.net - removing whitespace

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

Upvotes: 3

Views: 1772

Answers (2)

AGuyCalledGerald
AGuyCalledGerald

Reputation: 8150

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.

Upvotes: 1

Saeb Amini
Saeb Amini

Reputation: 24390

  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).

Upvotes: 3

Related Questions