我正在使用默认的 Rails EmailValidator 来检查我的电子邮件,就像这样
电子邮件验证器:
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors.add attribute, :invalid
end
end
end
和用户模型:
class User < ActiveRecord::Base
validates :email, presence: true, uniqueness: true, email: true
但这并没有将西里尔文电子邮件视为无效。我知道我可以用这个http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html更改正则表达式,但我想知道是否有最简单的方法,用 gem 或其他东西。我已经安装了 rfc-822 但现在我不知道如何使用它。这里的描述https://github.com/dim/rfc-822/blob/master/lib/rfc822.rb#L27说要添加validates_format_of :email, :with => RFC822::EMAIL
到模型但是当我这样做时,这就是我收到的
NameError: uninitialized constant User::RFC822
我错过了什么?