Email validation using ruby
The following piece of code validates any email that ends with .com, .edu, .org or any three letter extension. It uses regular expressions to find a match.
The following piece of code validates any email that ends with .com, .edu, .org or any three letter extension. It uses regular expressions to find a match.
RSS feed for comments on this post · TrackBack URI
Cheba said,
May 9, 2007 @ 6:35 am
‘ test@ test .com’ =~ /(.+)@(.+)\.(.{3})/
Note the spaces.
/(\A(\s*)\Z)|(\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z)/i
This one is more exact but is still not one that follows RFC.
John said,
September 13, 2007 @ 9:58 pm
This should allow for two letter domains, to take domains like .tv and .sc into account.
Validação de email com Ruby : Ruby Brasil said,
November 22, 2007 @ 4:08 pm
[...] via rubyonrailsexamples.com [...]
Harry said,
April 2, 2008 @ 1:38 am
%r{^(?:[_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-zA-Z0-9\-\.]+)*(\.[a-z]{2,4})$}i
this is the most appropriate one… with all the validations including the domain extensions…
Randal L Schwartz said,
April 18, 2008 @ 5:35 pm
As usual, every SINGLE email regex matcher here has FAILED to read RFC822. As with all the other versions, THIS REGEX IS WRONG. DO NOT USE THIS REGEX. DO NOT. AND PLEASE STOP POSTING BROKEN REGEX TO MATCH EMAIL HERE. {sigh}
Ezra Osiris said,
July 4, 2008 @ 8:14 am
Allows two letters domains please use of email =~ /(.+)@(.+)\.(.{2})/ instead of
email =~ /(.+)@(.+)\.(.{3})/ for three letters domains.
Thanks !