Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Validate Email Records

I know you can use PHP Email Validate filters to check if the data is abc @ abc . ext

Is there anyway I can run a MySQL query to do this, check for only that style format. Otherwise I will have to make a pagination and load balanced limit script to select all records from the DB (50,000+) and the server is already slow for my client on shared hosting.

I just want to see a list of only valid emails and also can I check for duplicates or similarities with like query?

Appreciate any collab on this.

like image 365
TheBlackBenzKid Avatar asked Dec 01 '11 08:12

TheBlackBenzKid


2 Answers

Somethis like this

SELECT * FROM users WHERE email NOT REGEXP '^[^@]+@[^@]+\.[^@]{2,}$';

OR

SELECT * FROM users WHERE email NOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';

Update. It's just an example,how to use regular expression in Mysql.

like image 137
Oyeme Avatar answered Sep 22 '22 15:09

Oyeme


You can use something like this

SELECT * FROM your_table
WHERE email_col LIKE '%@%.%'

to get (quite) valid emails, excluding the ones that are wrong for sure.
But you should check results to be sure of what you're showing...
Anyway, this is a starting point...

like image 36
Marco Avatar answered Sep 21 '22 15:09

Marco