Rails: How to validate format only if value is present?

You can use the option allow_blank: true to skip the validation when the attribute is blank/empty/nil.

https://guides.rubyonrails.org/active_record_validations.html#allow-blank

Leave a Comment