
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
active-model-email-validator
Advanced tools
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.
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
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.
If you like this gem, you may also want to check out Static Model, HTTP Error, or Email Test Helpers.
To send patches, please fork on GitHub and submit a pull request.
© 2011 Cody Robbins. See LICENSE for details.
FAQs
Unknown package
We found that active-model-email-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.