Sha256: 0abe9239ae1f5515e5496279d0b90842b81c379019bacac12626a44bc3c2d333
Contents?: true
Size: 666 Bytes
Versions: 23
Compression:
Stored size: 666 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] || 'is not a valid email address') 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
23 entries across 23 versions & 2 rubygems