问题描述
我已经写了一个普通的前pression允许最多3位小数。正则表达式是:
I have written a regular expression to allow maximum 3 decimal digits. The Regex is:
^\d+([.,]\d{1,3})?$
它完全正确的输入,例如(100,100.22等),也显示了验证错误,当用户尝试输入(0或,或10.11111)
It works perfectly for correct inputs such as (100,100.22 etc) and also shows up the validation error when the user tries to input (0. or , or 10.11111)
然而,当我试图进入的空间不会被显示错误。该表单不会被提交。有没有办法让用户明白是什么原因造成的错误。
However, the error does not get displayed when I am trying to enter spaces.The form doesn't get submitted. There is no way for a user to understand what is causing the error.
以下是我的code在aspx文件:
Following is my code in aspx file:
<td>
<asp:TextBox ID="txtBuildingSize" CssClass="textbox" runat="server"
ToolTip="in Sq Ft" meta:resourcekey="txtBuildingSizeResource1"></asp:TextBox>
<asp:Label ID="lblSqM1" runat="server" CssClass="optionLabel"
meta:resourcekey="lblSqM1Resource1" Text="square meters"></asp:Label>
</td>
<td>
<asp:RegularExpressionValidator ID="strBuildingSizeValidator"
ControlToValidate="txtBuildingSize" Display="Dynamic"
runat="server" ForeColor="Red" ValidationExpression="^\d+([.,]\d{1,3})?$"
meta:resourcekey="strBuildingSizeValidatorResource1"
Text="* Max 3 decimals only"></asp:RegularExpressionValidator>
这可能是什么问题?
What could be the problem?
解决: ^ \ D +([,] \ D {1,3} \ {0,0})$
Solved: ^\d+([.,]\d{1,3}\ {0,0})?$
的(空间){0,0}的伎俩。该错误消息出现了。
The (space){0,0} did the trick. The error message shows up.
推荐答案
解决方案由玛纳斯发现:
Solution found by Manasi:
^\d+([.,]\d{1,3}\ {0,0})?$
说明
Description
这篇关于普通防爆pression验证错误不会在进入一个空白现身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!