Last active
May 13, 2019 08:34
-
-
Save davydovanton/d051499a4747b392d708eaa97b12e26a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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