Skip to content

Instantly share code, notes, and snippets.

@davydovanton
Last active May 13, 2019 08:34
Show Gist options
  • Save davydovanton/d051499a4747b392d708eaa97b12e26a to your computer and use it in GitHub Desktop.
Save davydovanton/d051499a4747b392d708eaa97b12e26a to your computer and use it in GitHub Desktop.
# dry-validation (0.10.7)
# dry-types (0.10.3)
require 'dry/types'
require 'dry/validation'
module Types
include Dry::Types.module
Phone = String.constrained(format: /\A([\d]{10}|)\z/)
end
Create = Dry::Validation.JSON do
optional(:phone, Types::Phone).filled
end
p Create.(phone: '123')
# => #<Dry::Validation::Result output={:phone=>"123"} errors={}>
p Create.(phone: 'test phone with invalod chars 12324')
# => #<Dry::Validation::Result output={:phone=>"test phone with invalod chars 12324"} errors={}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment