Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have tried this, but if i am entering number, this alert message is been showed:

Allowed only 5 Decimal Places


and if i enter decimal this one:
Please enter the Gunta value between 0 and 40!


What to do?
XML
<asp:TextBox ID="txt_TotalArea" runat="server" CssClass="txtIp" MaxLength="20" onkeyPress="return allowOnlyNumber(event)" Style="width: 100px;">

<asp:RangeValidator runat="server" ID="RangeValidator6" ForeColor="Red" ControlToValidate="tb_TotalArea1" Type="Integer" MinimumValue="0" MaximumValue="40" ErrorMessage="Please enter the Gunta value between 0 and 40!" />

<asp:RegularExpressionValidator id="RegularExpressionValidator8" runat="server" ControlToValidate="tb_TotalArea1" ForeColor="Red"  ValidationExpression="(0|([1-9][0-9]{0,9}))(\.[0-9]{1,5})" ErrorMessage=" Allowed only 5 Decimal Places.">
Posted
Updated 23-Sep-15 23:21pm
v4

change type as double and only use below validator
ASP.NET
<asp:RangeValidator runat="server" ID="RangeValidator6" ForeColor="Red" ControlToValidate="tb_TotalArea1" Type="Double" MinimumValue="0" MaximumValue="40" ErrorMessage="Please enter the Gunta value between 0 and 40!" />
 
Share this answer
 
Hi,

Change your code to as follows.

XML
<asp:RangeValidator runat="server" ID="RangeValidator6" ForeColor="Red" ControlToValidate="txt_TotalArea" Type="Double" MinimumValue="0" MaximumValue="40" ErrorMessage="Please enter the Gunta value between 0 and 40!" />

<asp:RegularExpressionValidator id="RegularExpressionValidator8" runat="server" ControlToValidate="txt_TotalArea" ForeColor="Red" ValidationExpression="(^[0-9]\d{0,9}(\.\d{1,5})?%?$)" ErrorMessage=" Allowed only 5 Decimal Places." />


Thanks,
Sisir Patro
 
Share this answer
 
Comments
Ujjwal Saini 25-Sep-15 6:54am    
thanks...this worked
[no name] 26-Sep-15 0:54am    
Supreb. Accept the answer and upvote as well. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900