12

In Laravel 4 I'm trying to find not confirmation validation for input values. For example with confirmation we can check matching password and repassword and now I want to check contrary of two values. for example A must be not equal A in input values and after check in rules I must be return error. In this sample how to check that?

<input id="starttime_range"
       name="starttime_range"
       type="text"
       class="form-control"
/>

<input id="finish_range"
       name="finish_range"
       type="text"
       class="form-control"
/>

starttime_range must be not equal with finish_range

My code :

public function postInsert()
{
    $rules = array(
        'starttime_range' => 'required|integer',
        'endtime_range' => 'required|integer|not:starttime_range',
    );
    $validator = Validator::make(Input::all(), $rules);

    if ($validator->fails()) {
        return Redirect::back()
            ->withErrors($validator)
            ->withInput();
    } else {

    }
}
1
  • 1
    Would it make more sense to be sure endtime_range comes after starttime_range? Commented Sep 17, 2015 at 13:31

1 Answer 1

29

If you want campare two diffrent value, than you have to use different:

 $rules = array(
    'starttime_range' => 'required|integer',
    'finish_range' => 'required|integer|different:starttime_range',
);
Sign up to request clarification or add additional context in comments.

1 Comment

this is not working in Laravel v4.2 for different values its work fine but with deifferent values its also give same error

Your Answer

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