ministryofjustice/atet

View on GitHub
app/validators/post_code_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
class PostCodeValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value.blank?

    postcode = UKPostcode.parse(value)

    record.errors.add(attribute, :invalid) unless postcode.valid? && postcode.full?
  end
end