0

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
            )
        )
    );
} 
1
  • without knowing cakephp 2 validation.. 0,01 is not a natural number. also possibly you need to use a dot instead of comma for decimals. commas are to separate thousands. Commented Dec 2, 2016 at 1:08

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.