Sha256: d98f28464d5c87e0090587386857afba6e720c45a0e7e06eac917921273c0a44

Contents?: true

Size: 670 Bytes

Versions: 1

Compression:

Stored size: 670 Bytes

Contents

# Custom Validations for Email format
# This is not a great regular expression but it will work for now
#
# e.g. validates :home_email, :email_format => true
# e.g. validates :work_email, :email_format => { :allow_blank => true, :if => :method_returns_true }
class EmailFormatValidator < ActiveModel::EachValidator
  def validate_each record, attribute, value
    format = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
    message = attribute.to_s.humanize + ' doesn\'t match an acceptable format.'
    record.errors[attribute] << (options[:message] || message ) unless value =~ format
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
format_validators-0.0.8 app/validators/email_format_validator.rb