1

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, '')
R J.
  • 1,522
  • 10
  • 25
  • 40

4 Answers4

5

[-+]?([0-9]*\.[0-9]+|[0-9]+).

See Matching Floating Point Numbers With Regex

HamZa
  • 14,671
  • 11
  • 54
  • 75
ahPo
  • 374
  • 3
  • 9
1

This will find something like this 1234.5678
/\d+\.\d+/

HamZa
  • 14,671
  • 11
  • 54
  • 75
alex
  • 11
  • 1
0

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+\.$.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
0

I would try using the following:

\d+\.\d?{2}

http://rubular.com/r/a83BWznDuy

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497