Email Validation

メールのvalidation。
正答率82%

((561.0/(561+125))*100).round

設問

You are given several strings that may/may not be valid emails. You should write a regular expression that determines if the email id is a valid email id or not. You may assume all characters are from the english language.

Input sample:

Your program should accept as its first argument a filename. This file will contain several text strings, one per line. Ignore all empty lines. eg.

foo@bar.com
this is not an email id
admin#codeeval.com
good123@bad.com

Output sample:

Print out 'true' (all lowercase) if the string is a valid email. Else print out 'false' (all lowercase) .e.g.

true
false
false
true

やってみた

#!/usr/bin/env ruby
# http://stackoverflow.com/questions/1156601/whats-the-state-of-the-art-in-email-validation-for-rails

def valid_email?(email)
  !!email.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$/)
end

ARGF.lines do |line|
  puts valid_email?(line.chomp)
end

とりえあずinputはパスする通る形で最初書いていたのだが、

!!email.match(/^\w+@\w+\.\w+$/)

100点とならずに不正解だったので、こちらを参考にした。
参考URLは、改行の考慮がされているのだが
そんなのいらんだろと勝手に変更。
What's the state of the art in email validation for Rails? - Stack Overflow



余談だがgemもそれっぽいの沢山あるなぁ。
携帯キャリアがRFC準拠してなかったりするから
みんな適当な感じなのかな。
(あとで調べるか。)

email-validator (0.2.3, 0.2.2, 0.2.1, 0.2.0)

email_valid (0.0.1)
email_validation (1.1.1, 1.1.0, 1.0.0)
email_validator (1.3.0, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.1.0, 1.0.0)
email_veracity (0.6.0, 0.5.0, 0.4.0)
email_veracity_checker (0.0.2, 0.0.1)