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
  • 223,194
  • 41
  • 299
  • 337
user1269625
  • 3,121
  • 26
  • 79
  • 111

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}$/]
kittycat
  • 14,983
  • 9
  • 55
  • 80