portgas d ace portgas d ace - 1 year ago 45
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


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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download