class SsnValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /^\A([\d]{3}\-[\d]{2}\-[\d]{4}|[\d]{9})\Z$/ record.errors[attribute] << (options[:message] || I18n.t('flash_validators.errors.messages.ssn')) end end end