0

I am using code igniters form_validation and I was wondering if there was away to validate money for a text box for an example allow 4 numbers and then a period and then 2 numbers.

This what I got so far

regex_match[/^[0-9.]{0,7}+$/]

It works well, but I can enter a number like 100.000, is there anything I can do about it?

gen_Eric
  • 214,658
  • 40
  • 293
  • 332
user1269625
  • 2,981
  • 25
  • 76
  • 110

1 Answers1

1

To match exactly as you are requesting this would do it:

regex_match[/^\d{4}\.\d{2}$/] // allow 4 numbers only a period and then two numbers only

If you want to match UP TO 4 numbers so allow 1.00, 10.00, 100.00 but not more than 4 numbers before the decimal then use this:

regex_match[/^\d{1,4}\.\d{2}$/]
cryptic ツ
  • 14,925
  • 9
  • 50
  • 79