R J. R J. - 3 months ago 8
jQuery Question

Allow only 2 decimal points entry to a textbox using jquery?

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 (/(\.\d\d)\d+|([\d.]*)[^\d.]/, '$1$2');


You could do it without regex:

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