portgas d ace portgas d ace - 2 months ago 6
ASP.NET (C#) Question

Accept only one "." in Textbox that is accepting only numeric value

How can I accept only one "." in Textbox that is accepting only numeric value?
I am using an ajax tool called

FilteredTextBoxExtender


this is my sample code:

<asp:TextBox ID="txtMNumberOfHours" runat="server"
Width="50px" MaxLength="10"></asp:TextBox>

<asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server"
FilterType="Numbers, Custom" ValidChars="."
TargetControlID="txtMNumberOfHours" ></asp:FilteredTextBoxExtender>


in this code, I can enter multiple "." which is not good.

rs. rs.
Answer

How about using regexvalidator or maskededit extender?

With maskededitextender you can do

<asp:MaskedEditExtender ID="MaskedEditExtender1" 
   runat="server" TargetControlID="txtMNumberOfHours"
   Mask="99.99" MaskType="Number" InputDirection="RightToLeft" />

This will allow numbers with total four digits, 2 on left and 2 on right of dot.