Skip to content

Instantly share code, notes, and snippets.

@tan3
Created July 4, 2014 09:28
Show Gist options
  • Save tan3/e399e11290fb8b371ab1 to your computer and use it in GitHub Desktop.
Save tan3/e399e11290fb8b371ab1 to your computer and use it in GitHub Desktop.
Ruby: Validate email from csv
require 'csv'
VALID_EMAIL_REGEX = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/i
def valid_email?(email)
email =~ VALID_EMAIL_REGEX
end
# hier das textfile einlesen (liegt parallel zum script)
csv_text = File.expand_path("../liste.csv", __FILE__)
liste = CSV.read(csv_text, :encoding => 'utf-8')
liste.each_with_index do |row,index|
# row[2] ist 3. spalte in der csv
email = row[2]
puts "zeile #{index+1}: #{email} ist nicht gültig" unless valid_email?(email)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment