# Validate - simple & flexible input validation

**URL:** <https://forum.elixirforum.com/t/validate-simple-flexible-input-validation/55166>\
**Category:** Announcing\
**Tags:** library, validate\
**Created:** [April 10, 2023, 12:01pm UTC](https://forum.elixirforum.com/t/validate-simple-flexible-input-validation/55166 "2023-04-10T12:01:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![nehero](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nehero/32/30233_2.png) [@nehero](https://forum.elixirforum.com/u/nehero)\
**Post date:** [April 12, 2023, 8:21am UTC](https://forum.elixirforum.com/t/validate-simple-flexible-input-validation/55166/3 "2023-04-12T08:21:04Z")

</div>

you’re right that is a common issue, we could maybe add a built in `cast: :integer` rule that handles this automatically by trying to cast to the provided type, and returning a validation error if it fails.

in the mean time, you could accomplish this with a custom validation rule that passes the transformed value to the `success` result like:

```elixir
rules = %{
  "id" => [
    required: true,
    custom: fn %{ value: value } ->
      case Integer.parse(value) do
        {id, _} -> Validate.Validator.success(id)
        _ -> Validate.Validator.halt("must be an integer")
      end
    end
}

input = %{"id" => "123"}

{:ok, data} = Validate.validate(input, rules)

data["id"] == 123

```

---

_[View the full topic](https://forum.elixirforum.com/t/validate-simple-flexible-input-validation/55166)._
