How to validate decimals asp c #

2

I would like to know how to validate a decimal value in TextBox , what happens is that when I write a decimal example 12..00 or 12...55 my system goes down, I want to validate only the point and a single point in ASP C #.

<asp:TextBox ID="TxtMontoPagado" runat="server" placeholder="Monto Pagado"  Width="140px" Enabled="True"   class="form-control" title="Ingrese el Monto" data-error-msg="Ingrese el Monto" ></asp:TextBox>

<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender8" runat="server" FilterType="Numbers, Custom" ValidChars=".," TargetControlID="TxtMontoPagado" />
    
asked by PieroDev 25.03.2017 в 19:20
source

1 answer

2

You can use asp:RegularExpressionValidator to validate decimal values to two positions:

<asp:TextBox ID="TxtMontoPagado" runat="server" placeholder="Monto Pagado"  Width="140px" Enabled="True" class="form-control" title="Ingrese el Monto" data-error-msg="Ingrese el Monto" ></asp:TextBox>

<asp:RegularExpressionValidator ID="RegexDecimal" runat="server" ValidationExpression="((\d+)((\.\d{1,2})?))$" ErrorMessage="Ingrese un monto decimal" places." ControlToValidate="TxtMontoPagado" />

Update :

If you want to show the validation message in a alert you would have to add:

<asp:ValidationSummary runat="server" ShowMessageBox="true" ShowSummary="false" />

Below asp:RegularExpressionValidator . Here you can see the demo (give Run to run the project).

    
answered by 25.03.2017 / 19:56
source