Regex to allow only numbers and single dot when entering number to textbox in jquery.
Please suggest any regex to allow only numbers and single dot in textbox.
I have tried the following code.
$("#amountId").val().replace( /[^0-9]+/g, '')
Regex to allow only numbers and single dot when entering number to textbox in jquery.
Please suggest any regex to allow only numbers and single dot in textbox.
I have tried the following code.
$("#amountId").val().replace( /[^0-9]+/g, '')
[-+]?([0-9]*\.[0-9]+|[0-9]+).
This regex should do the trick for you, \d+\.$, and here is a Rubular to prove it. You could even consider prefacing the string with the ^ so that nothing can come before the digits too, like this, ^\d+\.$.