class ActiveModel::Validations::OnlyAlphaNumericValidator

文字列が半角英数字のみであることをチェックする

Public Instance Methods

validate_each(record, _attribute, value) click to toggle source
# File lib/moca_rlibs/active_model_validators/only_alpha_numeric.rb, line 9
def validate_each(record, _attribute, value)
  return if value.blank?

  value = value.presence.to_s
  return if value.match?(/\A[a-zA-Z0-9]*\z/)

  record.errors.add('contain invalid characters (only numbers and alphabets)')
end