codeforamerica/ohana-api

View on GitHub
app/validators/regex_validator.rb

Summary

Maintainability
A
35 mins
Test Coverage
A
100%
class RegexValidator < ActiveModel::EachValidator
  def regex_validate_each(regex, err_msg, record, attribute, value)
    return if value&.match?(regex)

    record.errors.add(attribute, (options[:message] || err_msg))
  end
end