RegularExpression to accepts only integer and float in ASP.Net

Last Reply one year ago By AnandM

Posted one year ago

Hi,

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.

Thanks.

Posted one year ago Modified on one year ago

Hi Swap,

Please refer below code

HTML

<div>
    <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">
    </asp:RegularExpressionValidator>
    <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" />
</div>

ScreenShot

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html