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

Version Path
challah-1.2.7 lib/challah/validators/email_validator.rb
challah-1.2.6 lib/challah/validators/email_validator.rb
challah-1.2.5 lib/challah/validators/email_validator.rb
challah-1.2.5.pre lib/challah/validators/email_validator.rb
challah-1.2.4 lib/challah/validators/email_validator.rb
challah-1.2.3 lib/challah/validators/email_validator.rb
challah-1.2.2 lib/challah/validators/email_validator.rb
challah-1.2.1 lib/challah/validators/email_validator.rb
challah-1.2.0 lib/challah/validators/email_validator.rb
challah-1.2.0.rc lib/challah/validators/email_validator.rb
challah-1.1.1 lib/challah/validators/email_validator.rb
challah-1.1.0 lib/challah/validators/email_validator.rb
challah-1.0.0 lib/challah/validators/email_validator.rb
challah-1.0.0.beta3 lib/challah/validators/email_validator.rb
challah-1.0.0.beta2 lib/challah/validators/email_validator.rb
challah-1.0.0.beta lib/challah/validators/email_validator.rb
challah-0.9.1.beta.3 lib/challah/validators/email_validator.rb
challah-0.9.1.beta.2 lib/challah/validators/email_validator.rb
challah-0.9.1.beta lib/challah/validators/email_validator.rb
challah-0.9.0 lib/challah/validators/email_validator.rb