1

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

2
  • Did you check online API docs or source code for a numeric or currency class? Chances are they have it built in (ie inflector class). Commented Nov 27, 2011 at 5:26
  • Numeric is what you want Commented Apr 28, 2016 at 4:09

2 Answers 2

2

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

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

Comments

0

Try this:

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

Hope it helps

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.