Reputation: 183
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
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
Reputation: 100175
Try this:
var $validate = array( 'amount' => array( 'rule' => array('decimal', 2) ) );
Hope it helps
Upvotes: 0