Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP Validate Email Address Format Using PHP Regular Expression preg_match

Validate Email Address Format Using PHP Regular Expression preg_match

This simple PHP function below will check to see if an email address is valid format/syntax or not by using PHP Regular Expression. It’s recommended to validate and check all input fields before inserting into the database especially with email address.

The function below will preg_match() PHP built in function to validate the format/systax of a email address by encoding its format in a regular expression. It looks for matches to the email pattern and will return true if matches are found, otherwise will return false.

PHP function to validate email address

<?php
function checkEmailAddress($email) {
	if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email))
		return true;
	return false;
}
?>

<?php function checkEmailAddress($email) { if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)) return true; return false; } ?>

Usage

<?php
$email = "[email protected]";
 
if(checkEmailAddress($email))
	echo $email . " is a valid email address!";
else
	echo $email . " is not a valid email address!";
 
?>

<?php $email = "[email protected]"; if(checkEmailAddress($email)) echo $email . " is a valid email address!"; else echo $email . " is not a valid email address!"; ?>

Download the php-validate-email-address

May 12, 2011Hoan Huynh
Schedule Backup And Zip MySQL Database In WindowsCreate And Assign Account To A User In Microsoft Dynamic CRM With C#
You Might Also Like:
  • CSharp Validate Email Address Function With Regular Expression
  • PHP validate ip address by using regular expression
  • Validate URL Use Regular Expression (Regex) In PHP
  • CSharp Validate Internet URL Function With Regular Expression
  • Validate email using regular expression in ASP.NET
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • Simple PHP Code Send Email
  • C# ASP.Net Validate Date
  • Validate Date With JQuery And Date Object
  • How To Track Website With Multiple Google Analytisc Accounts
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

11 years ago PHPemail address, preg_match, regular expression425
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,554 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,892 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,745 views
JQuery Allow only numeric characters or only alphabet characters in textbox
15,069 views
C# Read Json From URL And Parse/Deserialize Json
11,802 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development