Created
July 4, 2014 09:28
-
-
Save tan3/e399e11290fb8b371ab1 to your computer and use it in GitHub Desktop.
Ruby: Validate email from csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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