I would like to validate the format of a form value, allowing an empty value or requiring a specific format.
To validate a value against a format, this works fine:
You can use the option allow_blank: true to skip the validation when the attribute is blank/empty/nil.
allow_blank: true
https://guides.rubyonrails.org/active_record_validations.html#allow-blank