Class: Ezframe::EmailType

Inherits:
TextType show all
Defined in:
lib/ezframe/column_type.rb

Instance Attribute Summary

Attributes inherited from TypeBase

#attribute, #error, #parent

Instance Method Summary collapse

Methods inherited from TextType

#db_type, #value=

Methods inherited from TypeBase

#db_type, #db_value, get_class, #initialize, #key, #label, #make_error_box, #multi_inputs?, #no_edit?, #no_view?, #type, type_name, #use_view_format, #value, #value=, #view

Constructor Details

This class inherits a constructor from Ezframe::TypeBase

Instance Method Details

#email_format?(val) ⇒ Boolean

Returns:

  • (Boolean)


614
615
616
# File 'lib/ezframe/column_type.rb', line 614

def email_format?(val)
  return val.to_s =~ /^[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
end

#form(opts = {}) ⇒ Object



589
590
591
592
593
594
595
596
# File 'lib/ezframe/column_type.rb', line 589

def form(opts = {})
  return nil if no_edit? && !opts[:force]
  h = super
  return nil unless h
  h[:type] = "email"
  h[:class] = @attribute[:class] if @attribute[:class]
  return h
end

#normalize(val) ⇒ Object



598
599
600
601
# File 'lib/ezframe/column_type.rb', line 598

def normalize(val)
  return nil unless val
  return NKF.nkf('-w -Z4', val)
end

#validate(val) ⇒ Object



603
604
605
606
607
608
609
610
611
612
# File 'lib/ezframe/column_type.rb', line 603

def validate(val)
  super(val)
  return @error if @error
  return nil if !val || val.strip.empty?
  unless email_format?(val)
    @error = :invalid_value
    return @error
  end
  return nil
end