Skip to content

Commit

Permalink
Improved email validation
Browse files Browse the repository at this point in the history
  • Loading branch information
BDQ committed Oct 30, 2010
1 parent 05d6060 commit b8256a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
8 changes: 4 additions & 4 deletions app/models/mail_to_friend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class MailToFriend

validates :sender_name, :presence => true
validates :recipient_name, :presence => true
validates :sender_email, :format => { :with => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i }
validates :recipient_email, :format => { :with => /^([A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}[,;]?\s?)+$/i }
validates :sender_email, :format => { :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}$/i }
validates :recipient_email, :format => { :with => /^([-a-z0-9_+\.]+\@[-a-z0-9]+\.+[a-z0-9]{2,8}[,;]*)+$/i , :message => "contains invalid email address" }

def initialize(opts = {})
@sender_email = opts[:sender_email] || ' '
@sender_name = opts[:sender_name] || @sender_email.split('@', 2)[0].titleize
@recipient_email = (opts[:recipient_email] || ' ').gsub(';', ',')
@recipient_email = (opts[:recipient_email] || ' ').gsub(';', ',').gsub(/\s/ , "")
@recipient_name = opts[:recipient_name] || @recipient_email.split('@', 2)[0].titleize
@message = opts[:message]
end

def persisted?
false
end
Expand Down

0 comments on commit b8256a0

Please sign in to comment.