# Is there a way to validate int? and format? together

**URL:** <https://discourse.dry-rb.org/t/is-there-a-way-to-validate-int-and-format-together/607>\
**Category:** dry-validation\
**Created:** [August 12, 2018, 4:31pm UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-validate-int-and-format-together/607 "2018-08-12T16:31:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samnang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/samnang/32/293_2.png) [@samnang](https://discourse.dry-rb.org/u/samnang)\
**Post date:** [August 12, 2018, 4:31pm UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-validate-int-and-format-together/607/1 "2018-08-12T16:31:06Z")

</div>

This is my first time to try `dry-validation`, then I face an issue when I want to describe my schema to look like:

```auto
CardSchema = Dry::Validation.Schema do
  required(:exp_year).filled(int?, format?: /\A\d{4}\Z/)
end

```

Here is what the error message that I got `TypeError: no implicit conversion of Integer into String`.

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [August 14, 2018, 7:57pm UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-validate-int-and-format-together/607/2 "2018-08-14T19:57:22Z")

</div>

No, this is not supported. In dry-schema that will power dry-validation 1.0.0 I want to introduce this concept. We need a way to apply validation rules to input _prior_ coercion, and this is something that dry-validation cannot do right now.

---

<div class="post-metadata">

**Author:** ![samnang](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/samnang/32/293_2.png) [@samnang](https://discourse.dry-rb.org/u/samnang)\
**Post date:** [August 15, 2018, 2:46pm UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-validate-int-and-format-together/607/3 "2018-08-15T14:46:55Z")

</div>

Thank @solnic for the response, I can’t wait to see it in 1.0.0. In the mean time, here is what I come up:

```auto
required(:exp_year).filled(:int?)
validate(validate_exp_year: :exp_year) do |exp_year|
  exp_year.to_s.match?(/\A\d{4}\z/)
end

```
