Skip to content

Commit

Permalink
Use Ruby regex for email validation in guide example
Browse files Browse the repository at this point in the history
existing email regex allowed for invalid emails and invalidated valid emails

- The following emails are shown to be valid emails when they are not:
    - `email_<script></script>_123@example.co.in`
    - `email"123@example.com`
    - `email..123@example.com`
    - `.email123@example.com`
... and a few more

- The following email is shown to be an invalid email when it is valid:
    - `email@123.123.12.123`

Lets use the default ruby regex instead
  • Loading branch information
ryanong committed Dec 10, 2021
1 parent 1711737 commit d7d04e6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion guides/source/active_record_validations.md
Expand Up @@ -1094,7 +1094,7 @@ instance.
```ruby
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
unless value =~ URI::MailTo::EMAIL_REGEXP
record.errors.add attribute, (options[:message] || "is not an email")
end
end
Expand Down

0 comments on commit d7d04e6

Please sign in to comment.