forked from K-and-R/easy_captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request phatworx#19 from cluesque/plain_ruby_validator
Add a class method for simpler validation
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 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 |
---|---|---|
|
@@ -34,6 +34,23 @@ Or you can do this in a specific `validates` call: | |
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 | ||
|
||
```ruby | ||
EmailValidator.regexp # returns the regex | ||
EmailValidator.valid?('[email protected]') # boolean | ||
``` | ||
|
||
### Strict mode | ||
|
||
```ruby | ||
EmailValidator.regexp(:strict_mode => true) | ||
``` | ||
|
||
## Thread safety | ||
|
||
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. | ||
|
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
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