Sha256: d45a97cf5a59030e0a6aa8072482b0eda8cde984bba611f9d7941c2dbb7eec32

Contents?: true

Size: 890 Bytes

Versions: 40

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

module Spree
  # == An ActiveModel Email Validator
  #
  # === Usage
  #
  #     require 'spree/core/validators/email'
  #
  #     class Person < ApplicationRecord
  #       validates :email_address, 'spree/email' => true
  #     end
  #
  class EmailValidator < ActiveModel::EachValidator
    EMAIL_REGEXP = /\A([^@\.]|[^@\.]([^@\s]*)[^@\.])@([^@\s]+\.)+[^@\s]+\z/

    def validate_each(record, attribute, value)
      unless value =~ EMAIL_REGEXP
        record.errors.add(attribute, :invalid, { value: value }.merge!(options))
      end
    end
  end
end

# @private
EmailValidator = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(
  'EmailValidator',
  'Spree::EmailValidator',
  message: "EmailValidator is deprecated! Use Spree::EmailValidator instead.\nChange `validates :email, email: true` to `validates :email, 'spree/email' => true`\n"
)

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
solidus_core-2.9.6 lib/spree/core/validators/email.rb
solidus_core-2.8.6 lib/spree/core/validators/email.rb
solidus_core-2.9.5 lib/spree/core/validators/email.rb
solidus_core-2.9.4 lib/spree/core/validators/email.rb
solidus_core-2.6.6 lib/spree/core/validators/email.rb
solidus_core-2.7.4 lib/spree/core/validators/email.rb
solidus_core-2.8.5 lib/spree/core/validators/email.rb
solidus_core-2.9.3 lib/spree/core/validators/email.rb
solidus_core-2.9.2 lib/spree/core/validators/email.rb
solidus_core-2.10.0.beta1 lib/spree/core/validators/email.rb
solidus_core-2.7.3 lib/spree/core/validators/email.rb
solidus_core-2.6.5 lib/spree/core/validators/email.rb
solidus_core-2.9.1 lib/spree/core/validators/email.rb
solidus_core-2.9.0 lib/spree/core/validators/email.rb
solidus_core-2.9.0.rc.1 lib/spree/core/validators/email.rb
solidus_core-2.8.4 lib/spree/core/validators/email.rb
solidus_core-2.8.3 lib/spree/core/validators/email.rb
solidus_core-2.7.2 lib/spree/core/validators/email.rb
solidus_core-2.6.4 lib/spree/core/validators/email.rb
solidus_core-2.8.2 lib/spree/core/validators/email.rb