Reputation: 169
Does anyone know how to remove the white space for " Invalid zip." ? The reason is because there is another validation to the left of it to make sure it's only numbers. But if it's not visible I want the text to shift left. If you look above at DOB you can see that both validations were active so it looked ok. But I want invalid zip to shift left.
Here is the asp code:
<tr>
<td class="style2">Date of Birth [mm/dd/yyyy]</td>
<td class="style1">
<asp:TextBox ID="txtDOB" runat="server"
Width="268px" MaxLength="10"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ErrorMessage="Date of birth is required." ControlToValidate="txtDOB"
Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtDOB" Display="Dynamic"
ErrorMessage="Date of birth must be a valid date." ForeColor="Red"
MaximumValue="01/01/2013" MinimumValue="01/01/1909" Type="Date"></asp:RangeValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtDOB"
ErrorMessage="Spaces are not allowed!" ValidationExpression="[^\s]+" ForeColor="Red"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style2">Zip</td>
<td class="style1">
<asp:TextBox ID="txtZip" runat="server" Width="177px" MaxLength="9"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="Zip code is required." ControlToValidate="txtZip"
Display="Dynamic" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ControlToValidate="txtZip"
ErrorMessage="Spaces are not allowed!" ValidationExpression="[^\s]+" ForeColor="Red"></asp:RegularExpressionValidator>
<asp:RangeValidator ID="RangeValidator3" runat="server"
ErrorMessage="Invalid zip." ControlToValidate="txtZip" MaximumValue="999999999"
MinimumValue="0" SetFocusOnError="True" ForeColor="Red"></asp:RangeValidator>
</td>
</tr>
Here is what it looks like in VS2010
Upvotes: 0
Views: 3784
Reputation: 3479
You forgot to add 'Display="Dynamic"' to all your validators. The default is 'static' which reserves the space (which is causing the white space you are seeing). Add that to the RegularExpressionValidator and the RangeValidator and it should act like you want.
Upvotes: 8