Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
This gem uses the thorough email validation implemented by the email_regex gem written by Doug Wiegley which "provides a valid email regex that conforms to most valid RFC edges cases (disallows backticks), and allows for a few illegal patterns that are in common use".
Add this line to your application's Gemfile:
gem 'email_format'
And then execute:
$ bundle
Or install it yourself as:
$ gem install email_format
There's a valid?
method in the EmailFormat
module that accepts an email as an argument:
require 'email_format'
EmailFormat.valid?('invalid_email') # => false
EmailFormat.valid?('valid@email.com') # => true
Using it is as simple as using the validates
keyword in your model:
class User < ActiveRecord::Base
# ...
validates :email, email_format: true
# ...
end
Now the email attribute will be validated accordingly:
User.new('valid@email.com').valid? # => true
User.new('invalid_email@@').valid? # => false
By default, email_format
is pretty relaxed, but there is a strict
mode
class User < ActiveRecord::Base
# ...
validates :email, email_format: { strict: true }
# ...
end
Also, the model in question doesn't need to inherit from ActiveRecord::Base, you only need to include ActiveModel::Validations
in your class:
require 'email_format'
class Awesome
include ActiveModel::Validations
attr_accessor :email
validates :email, email_format: true
end
awesome = Awesome.new
awesome.email = "valid@email.com"
awesome.valid? # => true
awesome.email = "invalid_email"
awesome.valid? # => false
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that email_format 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.