Reputation: 2157
I am trying to validate a decimal value, i do use naturalNumber but did not recognize a value as 1,00 as greater than zero.
How can i work with decimal values using Cakephp 2 validation ? (0,01) would be accepted!
I try :
$this->loadModel('SomeModel');
$data = array(
'decimal_value' => '0,01',
);
$this->SomeModel->save($data);
class SomeModel extends AppModel {
public $validate = array(
'naturalNumber' => array(
'rule' => 'naturalNumber',
'message' => 'Value must be grater than 0',
'required' => true
)
)
);
}
Upvotes: 0
Views: 1555
Reputation: 60463
Decimals aren't natural numbers, natural numbers do not have fractions. Also 0,01
doesn't validate, Validation::naturalNumber('0,01')
returns false
.
If you want to validate decimals, use for example the decimal
rule (and if you do make sure that you set the proper locale if you expect commas as decimal separator), or even a custom regex.
See also
Upvotes: 1