Sha256: 27774a88a72126872340d98fceb3937799584f0e0822d46273d9a6042b9d14a2

Contents?: true

Size: 534 Bytes

Versions: 24

Compression:

Stored size: 534 Bytes

Contents

require 'active_support/core_ext/string/output_safety'

module HoboFields
  module Types
    class EmailAddress < String

      COLUMN_TYPE = :string

      def validate
        I18n.t("errors.messages.invalid") unless valid? || blank?
      end

      def valid?
        self =~ /^\s*([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*$/i
      end

      def to_html(xmldoctype = true)
        ERB::Util.html_escape(self).sub('@', " at ").gsub('.', ' dot ')
      end

      HoboFields.register_type(:email_address, self)

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
hobo_fields-1.3.3 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.2 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.1 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.RC4 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.RC3 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.RC2 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.RC1 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.RC lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre31 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre29 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre28 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre27 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre26 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre25 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre24 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre23 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre22 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre21 lib/hobo_fields/types/email_address.rb
hobo_fields-1.3.0.pre20 lib/hobo_fields/types/email_address.rb