bharanikumar Bs
bharanikumar Bs

Reputation: 183

cakephp validate number as well floating number, should not allow alphanumeric

how to validate amount in cakephp,

validation rule: should not accept empty space, should not alpha numeric, should not accept special character except dot(.),

example:

should accept below values

12 12.0 12.00 133

should not accept below values

123_33/#$#%#$%# a1a1455 asd fadsfads

actual thing is, this field for payment gateway, so before sending amount to payment gateway, we should make sure, we are sending decimal or full integer.

information: working in cakephp framkework

Upvotes: 1

Views: 7056

Answers (2)

aWebDeveloper
aWebDeveloper

Reputation: 38352

You will have to do the following

http://book.cakephp.org/2.0/en/models/data-validation.html#Validation::money

//2.0
    var $validate = array(
        'salary' => array(
            'rule' => array('money', 'left'),
            'message' => 'Please supply a valid monetary amount.'
        )
    );

If you are using 1.3 try

http://book.cakephp.org/1.3/en/The-Manual/Common-Tasks-With-CakePHP/Data-Validation.html#money

If can also try decimal http://book.cakephp.org/1.3/en/The-Manual/Common-Tasks-With-CakePHP/Data-Validation.html#decimal

//2.0
    public $validate = array(
        'price' => array(
            'rule' => array('decimal', 2)
        )
    );

Also consider Numeric http://book.cakephp.org/2.0/en/models/data-validation.html#Validation::numeric

Upvotes: 2

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

Try this:

    var $validate = array(
    'amount' => array(
    'rule' => array('decimal', 2)
    )
    );

Hope it helps

Upvotes: 0

Related Questions