2013-05-10 21 views
0

我要讓包含數值文本框,但它必須接受十進制數文本框的ASP網驗證,接受小數

有效:

  • 1.2
  • 1.23
  • 1.234
  • 0.0011等

但它會給錯誤消息,如果

  • 1,234
  • 1,23abc
  • 1.3454.21

這是我到目前爲止的代碼

<asp:TextBox Font-Bold="true" ID="TextBoxTaxValue" runat="server" CssClass="textBoxString" 
          Width="80px"></asp:TextBox><asp:Label ID="Label24" runat="server" Text="%"></asp:Label> 
         <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" 
          TargetControlID="TextBoxTaxValue" FilterType="Custom, Numbers" ValidChars="." /> 
         <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="One '.' only!" 
          ControlToValidate="TextBoxTaxValue" ValidationExpression="^(-)?\d+(\.\d\d)?$" /> 

請幫助我

+1

的,什麼是不工作?就像你對整數部分所做的那樣,用'\ d +'替換'\ d \ d'。 – 2013-05-10 02:12:34

+1

^- ?\ d +(\。\ d +)?$ – 2013-05-11 11:15:14

回答

0

<asp:RegularExpressionValidator> &
ValidationExpression試試像下面
(^[0-9]*[1-9]+[0-9]*\.[0-9]*$)|(^[0-9]*\.[0-9]*[1-9]+[0-9]*$)|(^[0-9]*[1-9]+[0-9]*$)