Email address validator that real world needs, for ActiveModel 3+.
Validating email address is hard. Its format definition varies on all kinds of systems depending on its generation, thus, hard. This validator does the job based on RFC 5322, but not exactly. It does few additional validations to make sure the email address works well on almost all kinds of systems, regardless its generations.
Read more about this on wikipedia.
- Ruby 2.4+
- ActiveModel 3+
gem install real_world_email_validator
or if you use bundler:
bundle add real_world_email_validator
class MyCompany
include ::ActiveModel::Model
attr_accessor :email
validates :email, real_world_email: true
end
my_company = MyCompany.new
my_company.email = '[email protected]'
my_company.valid?
=> true
my_company.email = 'fo [email protected]'
my_company.valid?
=> false