Sha256: f16afe4f81c2c95ce5dd79e7f198471d81b16cafea84e7682ad6c802e27698e8

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

module ActiveModel
  module Validations
    class EmailValidator < EachValidator
      def validate_each(record, attribute, value)
        if value.to_s !~ Validators::EMAIL_FORMAT
          record.errors.add(
            attribute, :invalid_email,
            :message => options[:message], :value => value
          )
        end
      end
    end

    module ClassMethods
      # Validates weather or not the specified e-mail address is valid.
      #
      #   class User < ActiveRecord::Base
      #     validates_email_format_of :email
      #   end
      #
      def validates_email_format_of(*attr_names)
        validates_with EmailValidator, _merge_attributes(attr_names)
      end

      alias_method :validates_email, :validates_email_format_of
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validators-0.1.3 lib/validators/validates_email_format_of.rb
validators-0.1.2 lib/validators/validates_email_format_of.rb
validators-0.1.1 lib/validators/validates_email_format_of.rb