Search code examples
phpvalidationlaravel-5

Check if a string is "0" with Laravel validation


How can I check if a value of a string is "0" in Laravel 5.3?

Here's my validation rules before processing the data:

// I want them to be anything but "0". So "01", "1" etc. are all okay
$rules = [
    'state' => 'required',
    'city' => 'required',
];

As the data is passed as strings I cannot use min:1 for this.

I'm sorry if this have already been asked, but I cannot find an answer. Many thanks!


Solution

  • This worked for me:

    $rules = [
        'state' => 'required|not_in:0',
        'city' => 'required|not_in:0',
    ];
    

    Also, have a look at this: Laravel 5.2 validation check if value is not equal to a variable