Sha256: 2b7bb97d67c70832ae6e760d19eb1ab8b973079aa2cab93b6a012ef2b818bed3

Contents?: true

Size: 565 Bytes

Versions: 11

Compression:

Stored size: 565 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 = URI::MailTo::EMAIL_REGEXP

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
solidus_core-3.1.9 lib/spree/core/validators/email.rb
solidus_core-3.1.8 lib/spree/core/validators/email.rb
solidus_core-3.0.8 lib/spree/core/validators/email.rb
solidus_core-3.0.7 lib/spree/core/validators/email.rb
solidus_core-3.1.7 lib/spree/core/validators/email.rb
solidus_core-3.0.6 lib/spree/core/validators/email.rb
solidus_core-3.1.6 lib/spree/core/validators/email.rb
solidus_core-3.0.5 lib/spree/core/validators/email.rb
solidus_core-3.1.5 lib/spree/core/validators/email.rb
solidus_core-3.0.4 lib/spree/core/validators/email.rb
solidus_core-3.1.4 lib/spree/core/validators/email.rb