Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

active-model-email-validator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

active-model-email-validator

  • 1.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Active Model Email Validator

This is a simple ActiveModel validator for email addresses built on top of the Mail gem. Instead of trying to devise an overly complex custom (and probably incorrect) regular expression to validate email addresses that is compliant with RFC 5321/5322—a difficult task—it instead relies on the Mail gem to parse the address. Since the Mail gem is an actively maintained library for working with email, if it can’t deal with an address it’s probably not worth attempting to send to anyways.

An additional check is performed to ensure that the domain name in the address has at least two components—that is, a top-level domain and one subdomain. The validator purposefully errs on the side of inclusivity rather than exclusivity: it might allow some invalid email addresses, but it hopefully doesn’t disallow valid addresses.

Full documentation is at RubyDoc.info.

Example

The following model uses ActiveModel::Validations::PresenceValidator and ActiveRecord::Validations::UniquenessValidator to ensure the presence and uniqueness of the user’s email attribute. The third line uses EmailValidator to check that the email address is valid.

class User < ActiveRecord::Base
  validates(:email,
            :presence   => {:message => "Email can't be blank"},
            :uniqueness => {:message => 'Email must be unique'},
            :email      => {:message => 'Email must be valid'})
end

Note

Currently there isn’t a validates_email class-level helper method because I’ve never had the need for it in practice, but I may add one at some point.

Colophon

See also

If you like this gem, you may also want to check out Static Model, HTTP Error, or Email Test Helpers.

Tested with

  • ActiveModel 3.0.5 — 20 May 2011

Contributing

To send patches, please fork on GitHub and submit a pull request.

Credits

© 2011 Cody Robbins. See LICENSE for details.

FAQs

Package last updated on 05 Jul 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc