If you want to make sure that an email passed in a form or url variable is actually what you expect it to be then this function can help.
function is_email($email) {
return preg_match('/^[a-z0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*\.[a-z0-9]+$/ui', $email);
}
It simply returns true if the supplied is an email address and nothing (false) if the data passed into it isn't one.
![Avatar of Clive Walkden](/assets/images/clive-walkden.jpg)
Clive Walkden
Posted:
Latest Articles
![Linux Linux command line tools, installations etc](https://clivewalkden.sirv.com/assets/images/blog/categories/linux.jpg?profile=personal)
Linux —
How to Install NordLayer VPN Client on Ubuntu 20.04 and Connect to a Virtual NetworkA simple to follow installation guide for NordLayer VPN
![avatar](https://clivewalkden.sirv.com/assets/images/clive-walkden.png?profile=personal&w=40&h=40)
Clive Walkden
Author
![MySQL MySQL usage, tweaks and learnings](https://clivewalkden.sirv.com/assets/images/blog/categories/mysql.jpg?profile=personal)
MySQL —
Mastering MySQL Database Imports on LinuxLearn efficient ways to import MySQL databases on Linux using the mysql command-line client. Explore the --source option and < operator for seamless data migration. Master MySQL imports on Linux with our comprehensive guide.
![avatar](https://clivewalkden.sirv.com/assets/images/clive-walkden.png?profile=personal&w=40&h=40)
Clive Walkden
Author
![DevOps DevOps principles and tool usage](https://clivewalkden.sirv.com/assets/images/blog/categories/devops.jpg?profile=personal)
DevOps —
Mastering SSH Key Conversions for DevOpsA guide to convert SSH keys from one version to another using Linux CLI
![avatar](https://clivewalkden.sirv.com/assets/images/clive-walkden.png?profile=personal&w=40&h=40)
Clive Walkden
Author