Skip to content

Instantly share code, notes, and snippets.

@JuzerShakir
Created October 23, 2021 18:50
Show Gist options
  • Save JuzerShakir/f952b8a67de87e0a49ff6a253298d046 to your computer and use it in GitHub Desktop.
Save JuzerShakir/f952b8a67de87e0a49ff6a253298d046 to your computer and use it in GitHub Desktop.
Used in medium
validates_each :email do | record, attr, value |
# extracts email service
service = value.match(/\A\w+\.?\w*\@{1}([a-z]+)\.{1}[a-z]+\z/).to_a[1]
# creates error for the attribute
record.errors.add(attr, "#{service} email service is not allowed!") if service.in? %w(yahoo msn aol hotmail)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment