从 MySQL 表中查找无效电子邮件地址列表?

mysqlmysqli database

要查找无效电子邮件地址,请使用以下语法 −

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

上述语法将给出所有无效电子邮件地址的列表。为了理解上述语法,让我们创建一个表。创建表的查询如下 −

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)

现在,您可以使用 insert 命令在表中插入一些记录。为了便于示例,我们还插入了一些无效的电子邮件地址。查询如下 −

mysql> select *from FindInvalidEmailAddressDemo;

以下是输出 −

+----+-------+-------------------+
| 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)

以下是查找无效电子邮件地址的查询 −

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

以下是无效电子邮件地址列表的输出 −

+-------------------+
| EmailAddress      |
+-------------------+
| 123Mike@gmailcom  |
| Bob909hotmail.com |
+-------------------+
2 rows in set (0.00 sec)

相关文章