Browse Source

Added email validation

Andrew Kane 7 years ago
parent
commit
211e1ee155
1 changed files with 7 additions and 0 deletions
  1. 7 0
      app/models/blazer/check.rb

+ 7 - 0
app/models/blazer/check.rb

@@ -4,6 +4,7 @@ module Blazer
     belongs_to :query
 
     validates :query_id, presence: true
+    validate :validate_emails
 
     before_validation :set_state
     before_validation :fix_emails
@@ -74,5 +75,11 @@ module Blazer
         # but we know what they mean, so let's fix it
         self.emails = emails.gsub(";", ",") if emails.present?
       end
+
+      def validate_emails
+        unless split_emails.all? { |e| e =~ /\A.+@.+\..+\z/ }
+          errors.add(:base, "Invalid emails")
+        end
+      end
   end
 end