Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal in javascript

Tags:

javascript

The text box should accept onli decimal values in javascript. Not any other special characters. It should not accept "." more than once. For ex. it should not accept 6.....12 Can anybody help???

like image 931
karthi Avatar asked Apr 29 '26 12:04

karthi


1 Answers

You can use regex:

function IsDecimal(str)
{
    mystring = str;
    if (mystring.match(/^\d+\.\d{2}$/ ) ) {
        alert("match");
    }
    else
    {
    alert("not a match");
    }
}

http://www.eggheadcafe.com/community/aspnet/3/81089/numaric-validation.aspx

like image 151
kemiller2002 Avatar answered May 01 '26 03:05

kemiller2002



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!