Skip to content

Commit

Permalink
update README.md and Changes.md
Browse files Browse the repository at this point in the history
  • Loading branch information
balexand committed Mar 2, 2019
1 parent 33b6c5b commit faa407b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
4 changes: 4 additions & 0 deletions Changes.md
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]
Expand Down
38 changes: 9 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit faa407b

Please sign in to comment.