Hey, 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"? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joe Peck wrote:> Hey, > > 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"?Hmm, I was wondering if validates_exclusion_of would work, or is that for something else? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It seems like this would be easy, I just can''t find info on how to do this... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 3, 2007, at 7:43 AM, Joe Peck wrote:> 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. -- def gw acts_as_n00b writes_at(www.railsdev.ws) end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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"Won''t this just validate that the email matches this format? I''m trying to get it so it accepts valid email addresses, but not if they''re from "baddomain.com" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 5, 2007, at 9:24 AM, Joe Peck wrote:>> 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" > > Won''t this just validate that the email matches this format? I''m > trying > to get it so it accepts valid email addresses, but not if they''re from > "baddomain.com"Duh. Brain fade. Use validates_each. validates_each :email do |model, attr, value| if value =~ /baddomain\.com/i model.errors.add(attr, "bad-domain.com not allowed") end end -- def gw acts_as_n00b writes_at(www.railsdev.ws) end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Willits wrote:> On Dec 5, 2007, at 9:24 AM, Joe Peck wrote: >> "baddomain.com" > Duh. Brain fade. Use validates_each. > > > validates_each :email do |model, attr, value| > if value =~ /baddomain\.com/i > model.errors.add(attr, "bad-domain.com not allowed") > end > end > > -- > def gw > acts_as_n00b > writes_at(www.railsdev.ws) > endThanks, it works like a charm. I didn''t even think of using "validates_each" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---