Regular Expression for accept value within range in ASP.Net

mukesh1
 
on Sep 20, 2022 02:35 AM
Sample_168670.zip
338 Views

Regular expression for marks 25 or less then 25, accept value only up to 2 decimal place.

Means it can accept all value less than 25 and 25 also.

24.34 is accepted and 24.345 is not accepted, coz 2 decimal places value is valid.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Sep 20, 2022 04:54 AM
on Sep 20, 2022 06:08 AM

Hi mukesh1,

If range goes above 25 it will display a error message. If range is below 25 it was accepted.

Please refer below sample.

HTML

<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
<asp:RegularExpressionValidator ControlToValidate="txtNumber" runat="server" ForeColor="Red"
    ErrorMessage="Only number between 0-25 with maximum 2 decimal places allowed."
    ValidationExpression="^(((2[0-4]|1[0-9]|[0-9]|0[0-9])|0|\.\d{1,2})($|\.$|\.\d{1,2}$))|((25|25.0|25.00)+$)"
    Display="Dynamic"></asp:RegularExpressionValidator>

Screenshot