2

I've a field which should accept Integer value and its sum with another field should be 100. In order to do this I've written custom method like this.

'share' => array(
    'share' => array(
        'rule' => array('share'),
        'message' => 'This field is required.',
        'last' => true, 
    ),

Here I want to use the built validation method to check weather this field is numeric.

function share() {
        if( $this->data['Model']['commission_type'] == "usage_based" ) {
            // if($this->data['SmeCommission']['share']) { // Want to check this is a valid integer How can I built in Numeric validation here
                // Next validation to sum is equal to 100 with another field in the data.
            // }
        } else { 
            return true;
        }
    }
2

1 Answer 1

2

Use multiple rules for that field. As shown below first rule checks the value is numeric and then your custom rule which checks the sum.

'share' => array(
    'numeric' => array(
        'rule' => 'numeric'
    ),
    'share' => array(
        'rule' => array('share'),
   )
),

If you do want to directly use a validation rule you can do like:

Validation::numeric(array('key' => 'value'));
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.