class User < ActiveRecord::Base
EXCLUDE_DOMAINS = %w{163.com mail.ru}
before_validation do
domains = EXCLUDE_DOMAINS.join('|')
pattern = %r{@#{domains}$}
if matched_domain = pattern.match(self.email)
self.errors.add(:email, "can't be #{matched_domain}")
end
end