Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Email validation with regex

I have a large list of emails I am running through. A lot of the emails have typos. I am trying to build a string that will check valid emails.

this is what I have for regex.

def is_a_valid_email?(email)   (email =~ /^(([A-Za-z0-9]*\.+*_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\+)|([A-Za-z0-9]+\+))*[A-Z‌​a-z0-9]+@{1}((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,4}$/i) end 

It passes if an email as underscores and only one period. I have a lot of emails that have more then one periods in the name itself. How do I check that in regex.

[email protected] # <~~ valid foo.bar#gmail.co.uk # <~~~ not valid [email protected] # <~~~valid  [email protected] # <~~ not valid  get_at_m.e@gmail  #<~~ valid 

Can someone help me rewrite my regex ?

like image 965
T0ny lombardi Avatar asked Apr 10 '14 16:04

T0ny lombardi


People also ask

How to check if an email is valid in Ruby?

Every email ID has three components: @ symbol, a prefix, and domain. The prefix appears to the left of the @ symbol, and the domain name is to the right of the symbol. Having an @ symbol is a must for an email ID to be valid.

How do I validate an email address in node?

How Do I Check if An Email is Valid in Node? You can verify email addresses in Node and perform Node email validation easily by utilizing Deep Email Validator. It can perform the validation effectively by checking the local part for common typos, DNS records, and the SMTP server response.


1 Answers

This has been built into the standard library since at least 2.2.1

URI::MailTo::EMAIL_REGEXP 
like image 91
Joshua Hunter Avatar answered Sep 23 '22 22:09

Joshua Hunter