Sha256: f8fd4c0498578f08c14c2d81cfcdcf3b9d37d834819031ca74b05154b629f3ad
Contents?: true
Size: 533 Bytes
Versions: 1
Compression:
Stored size: 533 Bytes
Contents
class Base64Validator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value.to_s) record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.base64')) end end private def valid_format?(value) value =~ /^(?:[A-Za-z0-9+$]{4})*(?:[A-Za-z0-9+$]{2}==|[A-Za-z0-9+$]{3}=|[A-Za-z0-9+$]{4})$/ end def valid_length?(value) value.present? end def valid?(value) valid_length?(value) && valid_format?(value) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_validation-4.0.0 | lib/active_validation/validators/base64_validator.rb |