Module: CMDx::Validators::Format
Overview
Validates that a value matches a specified format pattern
This validator ensures that the given value conforms to a specific format using regular expressions. It supports both direct regex matching and conditional matching with inclusion/exclusion patterns.
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ nil
Validates that a value matches the specified format pattern.
Instance Method Details
#call(value, options = {}) ⇒ nil
Validates that a value matches the specified format pattern
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cmdx/validators/format.rb', line 43 def call(value, = {}) match = if .is_a?(Regexp) value&.match?() else case in with:, without: value&.match?(with) && !value&.match?(without) in with: value&.match?(with) in without: !value&.match?(without) else false end end return if match = [:message] if .is_a?(Hash) raise ValidationError, || Locale.t("cmdx.validators.format") end |