How To Validate Number In Model

I would like to validate my numbers in my form with decimal places.

a user could enter a value for the first one (concentration)

can be max of 10 numbers . 8 numbers

1,000,000,000.12345678

the second is 3 numbers . 2 numbers

ie 100.25

The problem is that it can have a decimal or it doesn’t have to for whole numbers i.e 100 and it is also requiring a 0 after. so 100.0.

This validates properly except for a whole numbers WITHOUT a decimal it is requiring a decimal due to how I set it up.

How could I validate it to have or not have a decimal?




array('concentration', 'match', 'pattern'=>'/^[0-9]{0,10}(\.[0-9]{0,8})/'),

array('temperature', 'match', 'pattern'=>'/^[0-9]{0,3}(\.[0-9]{0,2})/'),



Thanks for your help in advance!

In regular expressions You can use ? for optional instance of some symbol or letter, so maybe it will help

This will help you

http://www.yiiframework.com/wiki/360/custom-number-formatting-or-decimal-separators-and-i18n/#hh1

Thanks, However, I already have the number formatting after it is pulled from the db. I just wanted to know a way to validate it with or with out a decimal.