-
-
Save dinedal/d75a81bffdaabd6f6c72 to your computer and use it in GitHub Desktop.
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
## Email validation | |
# | |
# Submitter: Paul Bergeron - paul.d.bergeron@gmail.com | |
# Website: pauldbergeron.com | |
# Github: https://github.com/dinedal | |
# Location: San Francisco - CA | |
# | |
# A few notes: | |
# | |
# Never use this in production. A real email validation method should actually | |
# make an attempt to resolve the hostname associated with email, | |
# as this is the only really 100% reliable way to ensure that a given email | |
# actually has a valid hostname. | |
# | |
# This does mean that `someone@com` would fail validation, but a real | |
# production service probably doesn't even want to attempt to send email to | |
# that address anyway. | |
class EmailValidator | |
def validate(email) | |
email = email.to_s.strip | |
regex = /^ # START | |
(".*" # username with quotes so special chars match | |
| # OR | |
[a-zA-Z0-9.+]*) # username no quotes | |
@ # @ | |
[a-zA-Z0-9.?]* # hostname or TLD | |
$ # END | |
/x | |
if regex.match(email) | |
true | |
else | |
false | |
end | |
end | |
end | |
email_validator = EmailValidator.new | |
File.open(ARGV.first).readlines.each do |line| | |
next if line.strip.empty? | |
puts email_validator.validate(line) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment