是否有人知道如何删除“无效的zip”空白区域。 ?原因是因为它左边有另一个验证,以确保它只是数字。但如果它不可见,我希望文本向左移动。如果您在DOB上方看到,您可以看到两个验证都处于活动状态,因此看起来没问题。但我希望无效的拉链向左移动。
这是asp代码:
<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>
这是VS2010中的样子
答案 0 :(得分:6)
您忘了向所有验证工具添加'Display =“Dynamic”'。默认为'static',它保留空间(导致您看到的空白区域)。将它添加到RegularExpressionValidator和RangeValidator,它应该按你想要的那样。