Find a list of invalid email address from a table in MySQL?

MySQLMySQLi Database

To find invalid email address, use the below syntax −

SELECT yourColumnName FROM yourTableName
WHERE yourColumnName NOT LIKE '%_@_%._%';

The above syntax will give the list of all invalid email addresses. To understand the above syntax, let us create a table. The query to create a table is as follows −

mysql> create table FindInvalidEmailAddressDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Name varchar(20),
   -> EmailAddress varchar(40),
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.75 sec)

Now you can insert some records in the table using insert command. We have inserted some invalid email address as well for our example. The query is as follows −

mysql> select *from FindInvalidEmailAddressDemo;

The following is the output −

+----+-------+-------------------+
| Id | Name  | EmailAddress      |
+----+-------+-------------------+
|  1 | John  | John12@gmail.com  |
|  2 | Carol | Carol@hotmail.com |
|  3 | Mike  | 123Mike@gmailcom  |
|  4 | Bob   | Bob909hotmail.com |
|  5 | David | David@gmail.com   |
+----+-------+-------------------+
5 rows in set (0.00 sec)

The following is the query to find the invalid email address −

mysql> select EmailAddress from FindInvalidEmailAddressDemo
   -> where EmailAddress NOT LIKE '%_@_%._%';

The following is the output with a list of invalid email address −

+-------------------+
| EmailAddress      |
+-------------------+
| 123Mike@gmailcom  |
| Bob909hotmail.com |
+-------------------+
2 rows in set (0.00 sec)
raja
Published on 26-Feb-2019 12:01:19
Advertisements