Sha256: 0c7ffa6d9501499e86c17abfa7a5988f427808687153e6d7a9fa413a8e417374
Contents?: true
Size: 755 Bytes
Versions: 11
Compression:
Stored size: 755 Bytes
Contents
class AlphaValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value, options) record.errors[attribute] << (options[:message] || I18n.t('flash_validators.errors.messages.alpha')) end end private def valid_format?(value, options) case options[:case] when :lower options[:strict] ? (value =~ /^[a-z]+$/) : (value =~ /^[a-z ]+$/) when :upper options[:strict] ? (value =~ /^[A-Z]+$/) : (value =~ /^[A-Z ]+$/) else options[:strict] ? (value =~ /^[A-Za-z]+$/i) : (value =~ /^[A-Za-z ]+$/i) end end def valid_length?(value) value != ' ' end def valid?(value, options) valid_format?(value, options) && valid_length?(value) end end
Version data entries
11 entries across 11 versions & 1 rubygems