I'm trying to update the validation of one of my models to not allow emails from "bad-domain.com"
I already have this in my model:
validates_format_of :email, :with => %r{\.(edu|com|gov|tv|biz|net|org|info|us|name|uk|jobs|tk|nz|de)$}i, :message => "Must be a valid email address"
That is working. But what kind of validation can I use to make sure that the :email doesn't contain "bad-domain.com"?
Unless I'm missing what you're trying to do, it would be the exact same approach:
validates_format_of :email, :with => /bad\-domain\.com$/i :message => "bad-domain.com not allowed"
You might want to add this too (verifies it's at least x@x.xx) and then your original one can test the TLD specifically.
validates_format_of :email, :with => /^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i :message => "Must be a valid email address"
Hmm, I was wondering if validates_exclusion_of would work, or is that for something else?
This is primarily for testing value lists. It verifies that the submitted value is within a specified set of options.