-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# HEAD | ||
|
||
# 2.0.0 | ||
|
||
* Looser validation [#49] | ||
|
||
# 1.6.0 | ||
|
||
* Unicode characters support [i7an #24] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,44 +20,24 @@ Then add the following to your model: | |
validates :my_email_attribute, email: true | ||
``` | ||
|
||
## Strict mode | ||
|
||
In order to have stricter validation (according to http://www.remote.org/jochen/mail/info/chars.html) enable strict mode. You can do this globally by adding the following to your Gemfile: | ||
|
||
```ruby | ||
gem 'email_validator', require: 'email_validator/strict' | ||
``` | ||
|
||
Or you can do this in a specific `validates` call: | ||
|
||
```ruby | ||
validates :my_email_attribute, email: {strict_mode: true} | ||
``` | ||
|
||
## Validation outside a model | ||
|
||
If you need to validate an email outside a model, you can get the regexp : | ||
|
||
### Normal mode | ||
If you'd like to validate an email outside of a model then here are some class methods that you can use: | ||
|
||
```ruby | ||
EmailValidator.regexp # returns the regex | ||
EmailValidator.valid?('[email protected]') # boolean | ||
``` | ||
|
||
### Strict mode | ||
|
||
```ruby | ||
EmailValidator.regexp(strict_mode: true) | ||
EmailValidator.valid?('[email protected]') # => true | ||
EmailValidator.invalid?('[email protected]') # => false | ||
``` | ||
|
||
## Thread safety | ||
## Validation philosophy | ||
|
||
This gem is thread safe, with one caveat: `EmailValidator.default_options` must be configured before use in a multi-threaded environment. If you configure `default_options` in a Rails initializer file, then you're good to go since initializers are run before worker threads are spawned. | ||
The validation provided by this gem is loose. It just checks that there's an `@` with something before and after it. See [this article by David Gilbertson](https://hackernoon.com/the-100-correct-way-to-validate-email-addresses-7c4818f24643) for an explanation of why. | ||
|
||
## Credit | ||
## Alternative gems | ||
|
||
Based on http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3 | ||
Do you prefer a different email validation gem? If so, open an issue with a brief explanation of how it differs from this gem. I'll add a link to it in this README. | ||
|
||
Regular Expression based on http://fightingforalostcause.net/misc/2006/compare-email-regex.php tests. | ||
## Thread safety | ||
|
||
This gem is thread safe. |