Class: FormKeeper::Constraint::Email

Inherits:
Base
  • Object
show all
Defined in:
lib/formkeeper.rb

Instance Method Summary collapse

Instance Method Details

#build_regexpObject



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/formkeeper.rb', line 253

def build_regexp
  wsp              = '[\x20\x09]'
  vchar            = '[\x21-\x7e]'
  quoted_pair      = "\\\\(?:#{vchar}|#{wsp})"
  qtext            = '[\x21\x23-\x5b\x5d-\x7e]'
  qcontent         = "(?:#{qtext}|#{quoted_pair})"
  quoted_string    = "\"#{qcontent}*\""
  atext            = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]'
  dot_atom_text    = "#{atext}+(?:[.]#{atext}+)*"
  dot_atom         = dot_atom_text
  local_part       = "(?:#{dot_atom}|#{quoted_string})"
  domain           = dot_atom
  addr_spec        = "#{local_part}[@]#{domain}"
  dot_atom_loose   = "#{atext}+(?:[.]|#{atext})*"
  local_part_loose = "(?:#{dot_atom_loose}|#{quoted_string})"
  addr_spec_loose  = "#{local_part_loose}[@]#{domain}"
  addr_spec_loose
end

#regexpObject



272
273
274
# File 'lib/formkeeper.rb', line 272

def regexp
  @regexp ||= build_regexp
end

#validate(value, arg) ⇒ Object



276
277
278
279
# File 'lib/formkeeper.rb', line 276

def validate(value, arg)
  r = ::Regexp.new('^' + regexp + '$')
  !!(value =~ r)
end