Skip to content

Boolean validation #113

Closed
Closed

Description

@saila-nasrin

Can't find any validator for boolean. Is it supported in this library or need custom implementation?

Activity

  1. devhammed commented on Apr 22, 2020

    @devhammed
    Contributor

    In all honesty, I also feel this should be part of the core rules but for the main time you can use the callback rule to check for boolean values. I once used below, you can tweak it to your needs:

    $validator = new Validator();
    $validation = $validator->validate($_POST, [
      'accept_terms' => [
        'required',
        function ($value) {
          return in_array($value, [true, false, 'true', 'false', '0', '1', 'y', 'n']);
        },
      ]
    ]);

    PS: Stolen from Laravel's boolean validation rule: https://laravel.com/docs/5.8/validation#rule-boolean

  2. zablondawit commented on Aug 24, 2020

    @zablondawit

    This should be included in the Core Rules.

  3. devhammed commented on Aug 24, 2020

    @devhammed
    Contributor

    @theZetrax I have just opened a pull request here, hopefully it would be merged ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions