# Is it possible to access the raw input before coercion?

**URL:** <https://discourse.dry-rb.org/t/is-it-possible-to-access-the-raw-input-before-coercion/427>\
**Category:** dry-validation\
**Created:** [December 6, 2017, 8:16am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-access-the-raw-input-before-coercion/427 "2017-12-06T08:16:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickenharp](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/rickenharp/32/12_2.png) [@rickenharp](https://discourse.dry-rb.org/u/rickenharp)\
**Post date:** [December 6, 2017, 8:16am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-access-the-raw-input-before-coercion/427/1 "2017-12-06T08:16:00Z")

</div>

I’m trying to validate a time parameter that should be iso8601 formatted. Is there a way to check the raw string input against a regex before it is coerced into a Time object when using Dry::Validation.Form? Because using

```auto
required(:from, :time).filled(:time?).format(/complicated_regex/)

```

will always be correctly formatted, since it’s the string representation of already coerced Time object.

---

<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:** [December 6, 2017, 10:19am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-access-the-raw-input-before-coercion/427/2 "2017-12-06T10:19:33Z")

</div>

Unfortunately no, but I’m glad you asked about this, as it is precisely one of the big things I’m planning to improve in dry-validation 1.0. There’s a big missing concept here, which is validating input _prior_ coercion. I don’t know how the API will look like, but something like this, more or less:

```ruby
required(:from).coerce_to(:time, format: :iso8601)

```

What will happen in such case, is that since there are no rules for the output value, it will assume that coercion and its result is everything we need to check, which is:

1. is the input value in the right iso8601 format?
2. is the output a time object?

---

<div class="post-metadata">

**Author:** ![rickenharp](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/rickenharp/32/12_2.png) [@rickenharp](https://discourse.dry-rb.org/u/rickenharp)\
**Post date:** [December 6, 2017, 10:26am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-access-the-raw-input-before-coercion/427/3 "2017-12-06T10:26:07Z")

</div>

Cool, I’m looking forward to that!

In the meantime, I solved this by defining a custom type like this:

```ruby
IsoTime = Types::Time.constructor do |values|
    begin
      ::Time.iso8601(values)
    rescue ArgumentError
      values
    end
  end

```

and using [type\_specs](http://dry-rb.org/gems/dry-validation/type-specs/) (which aren’t linked from the main navigation, btw):

```ruby
configure do
  config.type_specs = true
end

required(:from, Types::IsoTime).filled(:time?)

```

---

<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:** [December 6, 2017, 10:43am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-access-the-raw-input-before-coercion/427/4 "2017-12-06T10:43:25Z")

</div>

Ah yeah, custom types can be used for that…for now 🙂
