-2

I want to generate a regular expression for the following situation.

  1. a input box should accept numbers and dot in the following format XXX.XX.
  2. It accepts also numbers as XX
  3. It accepts also numbers as X
  4. It accepts also numbers XX.XX
  5. It accepts also numbers X.XX

I did like this: /[0-9]{3}\.[0-9]{2}$/, but it satisfied only point number 1.

HamZa
  • 14,671
  • 11
  • 54
  • 75
bappa147
  • 519
  • 3
  • 8
  • 18

1 Answers1

3

Try this:

^[0-9]{1,3}(\.[0-9]{1,2})?$
Andrew
  • 5,290
  • 1
  • 19
  • 22