Sha256: 0a24fd8a792abedafd41bab4886a9692c6ef57351082d33df8967fc05ce8d2fa
Contents?: true
Size: 651 Bytes
Versions: 14
Compression:
Stored size: 651 Bytes
Contents
module Challah # Used to validate reasonably-email-looking strings. # # @example Usage # class User < ActiveRecord::Base # validates :email, :presence => true, :email => true # end class EmailValidator < ActiveModel::EachValidator # Called automatically by ActiveModel validation.. def validate_each(record, attribute, value) unless value =~ EmailValidator.pattern record.errors.add(attribute, options[:message] || :invalid_email) end end # A reasonable-email-looking regexp pattern def self.pattern /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,}\z/ end end end
Version data entries
14 entries across 14 versions & 1 rubygems