Skip to content

Instantly share code, notes, and snippets.

@anaumov
Created January 31, 2013 09:30
Show Gist options
  • Save anaumov/4681641 to your computer and use it in GitHub Desktop.
Save anaumov/4681641 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
m = Mail::Address.new(value)
r = m.domain && m.address == value
t = m.__send__(:tree)
r &&= (t.domain.dot_atom_text.elements.size > 1)
rescue Exception => e
r = false
end
record.errors[attribute] << "Неверный формат email." unless r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment