-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
  • 13,530
  • 11
  • 51
  • 70
bappa147
  • 381
  • 3
  • 6
  • 17

1 Answers1

3

Try this:

^[0-9]{1,3}(\.[0-9]{1,2})?$
Andrew
  • 5,128
  • 1
  • 14
  • 21