Class: EmailPatternValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/email_pattern_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/validators/email_pattern_validator.rb', line 2

def validate(record)
  begin
    /#{record.email_regexp}/
  rescue RegexpError
    record.errors[:base] << "The Regexp is not vaild!"
  end
  cxt = V8::Context.new
  cxt['n'] = '01'
  [:uid_postparser, :department_code_postparser, :identity_detail_postparser, :started_at_postparser].each do |postparser|
    begin
      cxt.eval(record[postparser])
    rescue V8::Error
      record.errors[:base] << "The Regexp is not vaild!"
    end
  end
end