Allow only numbers and decimal point in ASP.Net TextBox

indradeo
 
on Jul 25, 2022 12:39 AM
747 Views

How to add validation number and decimal values only in TextBox using aspx.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
KasimA
 
on Jul 26, 2022 06:14 AM

Hi,indradeo

Please refer below sample. Use RegularExpressionValidator validator.

HTML

<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
<asp:RegularExpressionValidator ID="constr" runat="server" ValidationExpression="^\d*(\.\d+)?$"
    ErrorMessage="Please enter valid decimal number with any decimal places"
    ControlToValidate="txtNumber" ForeColor="Red"></asp:RegularExpressionValidator>

Screenshot