Search code examples
ruby-on-railsvalidationruby-on-rails-4

Check if email domain is valid


I have an input field for email_id in my form.
When the user enters the email id and submits the form, i need to validate the domain of the email.

(Note: I need not validate the email address. I need to Validate only the Domain)

What is the best way to check whether the Email-Domain is Valid or Not in Ruby on Rails?


Solution

  • There is a gem valid_email2 which has custom validations. It checks both MX records and A records. It also allows you to simply add blacklisted or whitelisted addresses as config in ymls. You can customize validation and validate according to the requirements. Check it's README for more.