-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,051
  • 11
  • 52
  • 72
bappa147
  • 431
  • 3
  • 7
  • 17

1 Answers1

3

Try this:

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