Sha256: 2f4419a44e8cb98a05608088f2a56633f085c0e2e477c64a2f732362b3b9b1f9

Contents?: true

Size: 335 Bytes

Versions: 4

Compression:

Stored size: 335 Bytes

Contents

class EmailValidator < ActiveModel::EachValidator
  VALID_EMAIL_REGEX = %r(\A[^@]+@(?:[^@]+\.)+[^@.]+\z)

  def validate_each(record, attribute, value)
    unless value =~ VALID_EMAIL_REGEX
      record.errors.add(attribute, error_message)
    end
  end

  private

  def error_message
    options.fetch(:messages, :invalid)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
htcht-0.1.6 lib/htcht/cli/rails/templates/api_build_files/email_validator.rb
htcht-0.1.3 lib/htcht/cli/rails/templates/api_build_files/email_validator.rb
htcht-0.1.1 lib/htcht/cli/rails/templates/api_build_files/email_validator.rb
htcht-0.1.0 lib/htcht/cli/rails/templates/api_build_files/email_validator.rb