I’m writting a small contact form from scratch and I needed a quick and dirty way to validate an email address with PHP
I’ve googled to find some examples and I found many examples for completing the task, however in order to validate the email address I eventually ended up with the following PHP code:
if ( preg_match( "/^[-w.]+@([A-z0-9][-A-z0-9]+.)+[A-z]{2,4}$/", $email ) )
{
# Do some processing here - input if valid
}
else
{
echo 'Incorrect email dying';
exit(1);
}
Now just pass the input $email variable from your form to the if condition and modify according to your needs.
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Hey long time now see, thanks for dropping back again! 🙂
More helpful Articles
- Saint Sergius of Radonezh The WonderWorker (Sergij Radonezhki) a quick helper saint in life problems, pupils, students in educational hardships, exams and Orphans. A short living of father of Russian monasticism
- How to properly control your Lenovo Thinkpad R61 fan rotation cycles on Linux with ThinkFan
- Fix eth changing network interface names from new Linux naming scheme ens, eno, em1 to legacy eth0, eth1, eth2 on CentOS Linux
- Great & Holy Thursday / Maundy Thursday (Thursday of Mysteries) day in the Orthodox Church
- How to disable Debian GNU / Linux (Squeeze) Apache 2 version reporting to improve security – Hide Apache server version
- Make custom installed Mozilla Firefox restore tab sessions on Debian GNU / Linux
- Few MySQL helpful commands in MySQL maintenance (MySQL rename Table, Empty MySQL Table Contents / Null Table records, Get info about variables in a Table, Change record in existing MySQL table, Get MySQL table privileges info, Some basic commands for MySQL issues debugging)
- How to convert AVI, MP4, FLV (flash video) and other non-free video encoded formats to Free Video format encoding OGV (Ogg Vorbis / Theora) on GNU / Linux and FreeBSD
- Qmail redirect mail to another one and keep local Mailbox copy with .qmail file – Easy Set up email forwarding Qmail
- Set proxy only for apt, apt-get, aptitude package manager on Debian / Ubuntu Linux
- ‘host-name’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’
- Technology one big freedom trap – Drop off technology to live true life
- How to Install and Use auditd for System Security Auditing on Linux
- What is wrong with todays Economy
Download PDF
Tags: How to validate a form email address with PHP / PHP Validate Email address
This entry was posted on Wednesday, August 18th, 2010 at 8:29 pm and is filed under Linux, Programming, Various. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.