R J. R J. - 4 months ago 12
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');

Answer

You could do it without regex:

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