RegularExpression to accepts only integer and float in ASP.Net

Last Reply on Jun 30, 2016 04:15 AM By AnandM

Posted on Jun 30, 2016 03:52 AM


Im having textbox.i want that textbox can accept only integer,floats 

and other textbox can accept only numbers and comma.

I also have RequiredFieldValidator as well as RegularExpressionvalidator on single control.

But i meant to say single digit as atlease one no.

i.e.when i enter only . in textbox it gets accepted.

atlease one number and then dot must be there.


Posted on Jun 30, 2016 04:15 AM Modified on on Jun 30, 2016 07:48 AM

Hi Swap,

Please refer below code


    <asp:TextBox ID="txtNumbers" ValidationGroup="Numbers" runat="server" />
    <asp:RegularExpressionValidator ControlToValidate="txtNumbers" ErrorMessage="Please Enter Correct Details"
        ValidationExpression="([0-9])[0-9]*[.]?[0-9]*" runat="server" ValidationGroup="Numbers">
    <br />
    <asp:RequiredFieldValidator ErrorMessage="Please Enter at Least One Digit" ControlToValidate="txtNumbers"
        ValidationGroup="Numbers" runat="server" />
    <br />
    <asp:Button ID="btnSubmit" Text="Submit" ValidationGroup="Numbers" runat="server" />