RegularExpression to accepts only integer and float in ASP.Net

Last Reply one year ago By AnandM

Posted one year ago


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 one year ago Modified on one year ago

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" />


I agree, here is the link: