Click here to Skip to main content
15,664,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,

I need to write a regular expression which will allow numbers like

99.99
100.00



thanx & regard
Posted

try this:
^\d+.\d+$

if you want to limit the decimal place to 2 only, then:
^\d+.\d{2}$
 
Share this answer
 
v2
Comments
Member 10251534 14-May-14 2:21am    
thanx dear...
This is for only decimal value
<asp:textbox id="TextBox1" runat="server" ></asp:textbox>
   <asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server" errormessage="only decimal value" controltovalidate="TextBox1" display="Dynamic" validationexpression="^\d+.\d{2}$" ></asp:regularexpressionvalidator>
 
Share this answer
 
v2
Try this

var intRegex = /^(?:[1-9]\d*(?:\.\d\d?)?|0\.[1-9]\d?|0\.0[1-9])$/;


In Client Side use JavaScript Code

JavaScript
$('#YourField').change(function () {
        var v = parseFloat(this.value);
        if (isNaN(v)) {
            this.value = '';            
        } else {
            this.value = v.toFixed(2);           
        }
    });
 
Share this answer
 
v3
Comments
Member 10251534 13-May-14 10:29am    
sir i want allow only decimal value,not integer value in textbox
Vi(ky 13-May-14 10:39am    
you want it client side or server side?
Member 10251534 13-May-14 10:40am    
Client Side
Vi(ky 13-May-14 10:41am    
Please see the update solution
try with

[0-9]+(\.[0-9][0-9]?)?

OR

^[0-9]+(\.[0-9]{1,2})?$
 
Share this answer
 
v2
Comments
Member 10251534 13-May-14 10:29am    
sir i want allow only decimal value,not integer value in textbox

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