Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  112] [ 2]  / answers: 1 / hits: 44815  / 11 Years ago, thu, june 13, 2013, 12:00:00

Allow only 2 decimal points when entering number to a textbox using jquery.



Please suggest any regex to allow only two decimal in textbox.



I have tried the following code.



$(#amountId).val().replace (/(.dd)d+|([d.]*)[^d.]/, '$1$2');

More From » jquery

 Answers
9

You could do it without regex:



var dec = parseFloat($(#amountId).val(),10).toFixed(2);

[#77641] Wednesday, June 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sylviakaitlinj

Total Points: 564
Total Questions: 114
Total Answers: 105

Location: Jordan
Member since Thu, Aug 11, 2022
2 Years ago
;