k-and-r / email_validator Goto Github PK
View Code? Open in Web Editor NEWAn email validator for Rails.
License: MIT License
An email validator for Rails.
License: MIT License
Hi there! First of all, thanks for the great gem!
I've found a couple more of popular disposable email domains and it would be nice to add them to the list:
10minutemail.net
temp-mail.org
10minutemail.com
minuteinbox.com
10minutesemail.net
Currently in strict
mode:
EmailValidator.valid?("[email protected]", mode: :strict)
=> false
but 2020.example.com
is indeed a valid FQDN, right?
Currently the regex allows trailing and leading whitespace. e.g. "\[email protected]\n " is allowed. Is this on purpose? The mail servers I use reject such emails.
Tested against 1.2.3 (was working in 1.1.0)
The following address now fails validation:
This seems to be related to the length of the "co" part, since the following succeeds:
.. Gavin
I found test_[email protected]
passes the validation. The email has multi-byte underbar before the at-mark.
(The validation fails if I set strict mode)
AWS SES rejected the email address so I wonder what is the expected result.
Emails from domains like 163.com, 139.com are marked as invalid. But they are valid: those are common emails in China :)
I've created a failing PR for this
This means that valid email addresses like evan.o'[email protected]
are considered invalid in strict mode.
PR inbound.
After we upgraded to Rails 6, we noticed that email validation stopped working silently for email input like: base@example
:(
When I enter an email with an IDN like "test@umläut.com" in a form in my Rails app and submit it, the backend receives the ACE representation "[email protected]", which is considered invalid by email_validator in strict mode:
EmailValidator.default_options[:mode] = :strict
> EmailValidator.valid?("[email protected]")
false
> EmailValidator.valid?("test@umläut.com")
true
Is this a bug?
Since the mail
gem used by ActionMailer
etc doesn't support UTF8 addresses (mikel/mail#1014) could be nice have them invalidated.
http://ru.wikipedia.org/wiki/IDN
It seems email_validator
does not consider emails like "user@domain.рф" as valid email addresses.
So, in model:
validates :email, :email => true, :uniqueness => true
and then in console:
[44] studium » u.valid?
User Exists (0.8ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = '[email protected]' AND "users"."id" != 18) LIMIT 1
=> true
[45] studium » u.email = 'user@domain.рф'
=> "user@domain.рф"
[46] studium » u.valid?
User Exists (0.7ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'user@domain.рф' AND "users"."id" != 18) LIMIT 1
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'user@domain.рф' AND "users"."id" != 18) LIMIT 1
=> false
[47] studium » u.errors.full_messages
=> [
[0] "Email имеет неверное значение"
]
Would it be possible to add an allow_blank
configuration option that would treat "" as a valid email?
I see that it's possible to do validates :attribute, email: { allow_nil: true}
, but for consistency with other gems like phonelib it would be nice if email_validator
accepted both ""
and nil
as valid.
In line 2 where you define EmailValidator as a subclass of ActiveModel, I get an error "uninitialized constant ActiveModel (NameError)" - I have a very lean application and removed ActiveModel from the project. I think this is working for other people because it's using the ActiveModel that other gems have required. Just doing a require 'active_model'
before the class definition should fix this.
With the introduction of testing on ppc64le
(added in PR #69), while building on TravisCI, we are seeing that Bundler will sometimes pull in activerecord > 5
, which should not happen. This is not consistent.
Here is an example of failures for both 2.4.7
and 2.4.10
Build number 153: https://travis-ci.com/github/K-and-R/email_validator/builds/222180216
Yet here, with only a change to the README
, only 2.4.10
gets activerecord > 5
. This seems to be a bug in TravisCI.
Build number 154: https://travis-ci.com/github/K-and-R/email_validator/builds/222703882
I would expect that Bundler behave in a consistent manner across builds for the same Ruby version.
I am going to continue to monitor this. I will also try to find time to research what the cause may be. Right now, I am considering this a low priority since it doesn't impact the actual gem functionality.
(cc: @nageshlop)
Validation not catching
in Gemfile:
gem 'email_validator', git: '[email protected]:balexand/email_validator.git'
in model:
validates :email, email: true
Error:
Exception encountered: #<ArgumentError: Unknown validator: 'EmailValidator'>
backtrace:
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.14/lib/active_model/validations/validates.rb:96:in `rescue in block in validates'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.14/lib/active_model/validations/validates.rb:93:in `block in validates'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.14/lib/active_model/validations/validates.rb:90:in `each'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.14/lib/active_model/validations/validates.rb:90:in `validates'
/Users/mzhukov/Work/RoR/libapp/app/models/reader.rb:4:in `<class:Reader>'
/Users/mzhukov/Work/RoR/libapp/app/models/reader.rb:1:in `<top (required)>'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:359:in `require_or_load'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:192:in `block in const_missing'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:190:in `each'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:190:in `const_missing'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:229:in `each'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:229:in `constantize'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:260:in `safe_constantize'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.14/lib/action_controller/metal/params_wrapper.rb:152:in `_default_wrap_model'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.14/lib/action_controller/metal/params_wrapper.rb:169:in `_set_wrapper_defaults'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.14/lib/action_controller/metal/params_wrapper.rb:133:in `inherited'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.14/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.14/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
/Users/mzhukov/Work/RoR/libapp/app/controllers/readers_controller.rb:1:in `<top (required)>'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:359:in `require_or_load'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:192:in `block in const_missing'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:190:in `each'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:190:in `const_missing'
/Users/mzhukov/Work/RoR/libapp/spec/controllers/readers_controller_spec.rb:3:in `<top (required)>'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:245:in `load'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:245:in `block in load'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:245:in `load'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `block in load_spec_files'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `each'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load_spec_files'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in `run'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/test_framework/rspec.rb:11:in `run_tests'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/run_strategy/forking.rb:13:in `block in run'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/forker.rb:21:in `block in initialize'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/forker.rb:18:in `fork'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/forker.rb:18:in `initialize'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/mzhukov/.rvm/gems/ruby-2.0.0-p0/gems/spork-1.0.0rc4/lib/spork/server.rb:49:in `run'
/Users/mzhukov/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1588:in `perform_without_block'
/Users/mzhukov/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1548:in `perform'
/Users/mzhukov/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
/Users/mzhukov/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1622:in `loop'
/Users/mzhukov/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1622:in `block in main_loop'
Hi 👋
Just found out that there is a gem that allows to not only be sure that email domain exists, but even such email identifier is real in that domain (like email ping or something) 🤔
Support client-side validations using https://github.com/bcardarella/client_side_validations.
I think it would be prudent to include a security warning in your readme. This validation philosophy could leave your users open to XSS attacks, depending on their use case.
The regexp being used for validation will allow javascript email addresses.
Is this gem compatible with rails 4?
rails new emailtest
cd emailtest
rails -v #Rails 4.0.2
add gem 'email-validator' to Gemfile
bundle install
rails g scaffold User email:string
add to user.rb: validates :email, email: true
rake db:migrate
rails s
error at localhost:3000/users
undefined method `new' for EmailValidator:Module
the line highlighted is in user.rb:
validates :email, email: true
I've been using the validates_email_format_of
gem for very very long time.
How does it compare?
RFC 2822
and RFC 3696
Invalid email address pippo,[email protected]
(includes a comma) passes validation, which is wrong according to http://www.remote.org/jochen/mail/info/chars.html
As said on the page http://www.remote.org/jochen/mail/info/chars.html (strict validator is based on it as said in README):
[Dots are] allowed in email addresses. Often used for addresses with the format '[email protected]'. There is one restriction however: Two dots next to each other or a dot at the beginning or end of the local part are not allowed by RFC2822. The reason is that in RFC2822 the dot is used as a separator for tokenizing the mail address. Dots at the named locations would mean an empty token, which is not allowed. Still, there are people who use it. Some MTAs accept it, some don't.
But currently such emails are treat as good:
> EmailValidator.regexp(strict_mode: true) =~ '[email protected]'
# => 0
And I see a lot of Net::SMTPError: bad address
errors in log when trying to send emails. I filtering emails from user input with strict mode.
I think taht such emails should be forbidden in strict mode. What do you think?
I have a scenario to validate if email exist on company domain. for example any email end with @gmail.com
Using the gem as it is (not on strict mode), it appears that .tech domains are not allowed and appear as invalid during validation.
mailto:[email protected]
should not be a valid mail.
The validator says that there is no problem with this email. Is this a bug?
He is currently allowing emails like test [email protected]
.
the gem should use I18n or accept a lambda/ proc to be passed as :message
Hi 👋 ,
We've been using this gem for a while, then we started getting some "hackerish" invalid emails in our database as a result we had to look for alternative validations. At first we used the Ruby built-in regex URI::MailTo::EMAIL_REGEXP
but this one has some use cases where it does not work with a valid email.
Looking at the source code I am under the impression this gem's regex is very simplistic "no spaces" plus "@ symbol" followed by "no spaces". That may result in invalid emails, also allows for stuff like <script>alert()</script>@domain.com
.
I would like to promote this alternative https://github.com/afair/email_address that includes a Rails validator and has some other goodies like emails types, hashing, etc.
Thanks for sharing your project 💜
I kept getting this error undefined method my_email_attribute' for #User:0x00007fd032841908` could anyone help
Right now we have to split out validations to avoid 2 error messages. Consider the following:
validates :email, presence: true, uniqueness: true, email: true
On a blank email submission, this will generate ["Email is blank", "Email is invalid"]
for the error messages. Creates a bit of confusion and generally isn't desirable for users. To avoid this, we have to split it out into 2 validations.
validates :email, presence: true, uniqueness: true
validates :email, email: true, if: :email? # split out in case email is blank
Any chance we could add some smarts to only run the validation if email is present? I guess we could also drop the presence: true
specifier, but then the error message won't be quite accurate ("blank" is more accurate than "invalid")
Hey, I am using email_validator in my application and according to the documentation , '#' isn't allowed in strict mode. Somehow though test.1#@mailinator.com passes the validation.
In version 2.0.1
: foo@example
comes back valid
In versions 1.6.0
and 2.0.1
: foo;@example.com
comes back valid, but is invalid in version 1.4.0
Example from my specs:
User validations should not allow :email to be ‹"foo"›, ‹"foo@"›, ‹"foo@example"›, ‹"[email protected]"›, or ‹"example.com"›
Failure/Error:
is_expected.not_to allow_values(
"foo",
"foo@",
"foo@example",
"[email protected]",
"example.com",
).for(:email)
After setting :email to ‹"foo@example"›, the matcher expected the User
to be invalid, but it was valid instead.
After I updated from version 1.6.0 to 2.0.1 I got some false positives on the email validation. I have a test on my application that doesn't let an object with an invalid email be saved.
Previously with the version 1.6.0 the tests were running as expected (object wasn't being created). The email that I use for this test is "b@man".
But now, the version 2.0.1 says this is a valid email, which makes my test fails and also, this is not a valid email, so this is an issue with the gem.
I did some other tests and these are the results:
Version 1.6.0
[STAG]US:(ec)[1] pry(main)> EmailValidator.valid?('b@man')
=> false
[STAG]US:(ec)[2] pry(main)> EmailValidator.valid?('email@[email protected]')
=> false
Version 2.0.1
USOps:(ec)[31] pry(main)> EmailValidator.valid?('b@man')
=> true
USOps:(ec)[32] pry(main)> EmailValidator.valid?('email@[email protected]')
=> true
According to the linked docs, apostrophes are "maybe" allowed in emails. However, personal experience shows that certain main email vendors will allow '
in the local part of an email (gmail won't, but will deliver to one).
It would be cool to have an rspec matcher included with the gem.
This is how an older gem is solving this: https://github.com/validates-email-format-of/validates_email_format_of/blob/master/lib/validates_email_format_of/rspec_matcher.rb
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.