ElxValidation.Boolean (elx_validation v0.1.0)

boolean

  • The field under validation must be able to be cast as a boolean. Accepted input are true, false, 1, 0, "1", and "0".
    data = %{
      is_ok1: "true",
      is_ok2: true,
      is_ok3: "false",
      is_ok4: false,
      is_ok5: 0,
      is_ok6: 1,
      is_ok7: "0",
      is_ok8: "1",
      is_ok9: "yes",  ---> return error
    }
    rules = [
      %{
        field: "is_ok1",
        validate: ["boolean"]
      },
      %{
        field: "is_ok2",
        validate: ["boolean"]
      },
      %{
        field: "is_ok3",
        validate: ["boolean"]
      },
      %{
        field: "is_ok4",
        validate: ["boolean"]
      },
      %{
        field: "is_ok5",
        validate: ["boolean"]
      },
      %{
        field: "is_ok6",
        validate: ["boolean"]
      },
      %{
        field: "is_ok7",
        validate: ["boolean"]
      },
      %{
        field: "is_ok8",
        validate: ["boolean"]
      },
     %{
        field: "is_ok9",
        validate: ["boolean"]
      },
    ]

Link to this section Summary

Functions

Boolean data : true , "true" , false ,"false" , 1 , "1" , 0 or "0"

Link to this section Functions

Link to this function

validate_boolean(target)

Boolean data : true , "true" , false ,"false" , 1 , "1" , 0 or "0"