Friday, June 21, 2019

Email id validation using php - Sample code

PHP - Validate E-mail

The easiest and safest way to check whether an email address is well-formed is to use PHP's filter_var() function.  In the code below, if the e-mail address is not well-formed, then store an error message:

Sample Program: #1

$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $emailErr = "Invalid email format";
}

Sample Program: #2

// PHP program to validate email
// Function to validate email using regular expression
function email_validation($str) {
    return (!preg_match(
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $str))
        ? FALSE : TRUE;
}
 
// Function call
if(!email_validation("author@evergreenphp.com")) {
    echo "Invalid email address.";
} else {
    echo "Valid email address.";
}

Sample Program: #3
 
$email_a = 'sir@evergreenphp.com';
$email_b = 'yourfriend';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
    echo "Email ID '$email_a' is considered valid.\n";
}

if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
    echo "Email ID '$email_b' is considered valid.\n";
} else {
    echo "Email ID '$email_b' is considered invalid.\n";
}

23 comments:

Aryan Garg said...

Nice blog! Very interesting and informative post

Ecommerce development in india
Madrid Holiday Packages
Royal Wedding Planners in Delhi

D Phanchalad said...

Great Blog!! That was amazing. Your thought processing is wonderful. The way you tell the thing is awesome. You are really a master.

Best Digital Marketing Course Noida
Web Designing Course in Noida
Spoken english course Noida
Best Digital Marketing course Noida Sector 2
Best Digital Marketing Course Noida Sector 15
Digital Marketing Institute New ashok Nagar

ANSON SPORTS said...

Great Blog , very informative.

Anson Sports is the established brand in the field of gym equipment manufactureres in india.We provide wide range of gym equipments liks treadmill, dumbell,weights,gym clothing and much more.To know more about us visit at.

buy online fitness equipments
Buy sports goods online
Buy home gym equipments online in india
Buy online fitness equipments in india

YOGESH GAUR said...

Yogesh Gaur is the famous digital marketing consultant based in New Delhi. I usually gives digital marketing techniques in order to rank higher in search engines.I write blogs on social media marketing,email marketing,search engine optimization,content marketing and much more.I usually give tips and tricks to money online.To know more visit at:

Classified sites uk
Forum posting sites 2018
ppt site
usa free classified ads sites without registration
free ad posting without registration

ANSON SPORTS said...

Anson Sports is the established brand in the field of gym equipment manufacturers in india.We provide wide range of gym equipments like treadmill, dumbell,weights,gym clothing and much more.To know more about us visit at.

Buy online treadmill in india

Home gym packages in india

fitness equipment stores in india

Roshni Khanna said...

Exceptional post however I was wanting to know if you could write a little more on this subject? I’d be very grateful if you could elaborate a little bit further. Many thanks!

http://www.hentai-foundry.com/user/siyasingh/blogs/14619/Questions-to-Ask-Before-Meeting-An-Escort |

https://www.knowpia.com/s/blog_4260635964e49fd2 |

https://www.reddit.com/user/iamkritisenan/comments/ici47v/questions_to_ask_before_meeting_an_escort/ |

https://infeeds.com/u/shilpamalhot/questions-ask-before-meeting-escort-52756?ref=pub&feed&st=published |

https://www.techsite.io/p/1645401/t/questions-to-ask-before-meeting-an-escort |

french bulldog puppies for sale said...

its been long since i saw a post that's so educative and informational. i will make sure to share this my facebook group. you can also view contents on our websites below.

French Bulldog Puppies For Sale

French Bulldog Breeders

French Bulldog Puppies For Sale Near Me

French Bulldog Puppies For adoption

French Bulldog Puppies


Blue French Bulldog Puppies

SNK Social Fame said...

Really useful information. Thank you so much for sharing. It will help everyone. Keep Post.
Buy Instagram Followers India

Digital Agency In India said...

It was so good to read and useful to improve my knowledge as updated one, keep blogging.
Digital Agency In India

Cre8tivebot said...

Good Job! I will refer the people to the best IT Solutions providers click the below link:

IT Consulting Melbourne
affordable seo packages
ppc company australia
content marketing agency melbourne
social media marketing company
web development australia
app development melbourne
seo packages
social media marketing packages
Cre8tivebot

evoseedbox said...

Such a wonderful information blog post on this topic provides assignment service at affordable cost in a wide range of subject areas for all grade levels, we are already trusted by thousands of students who struggle to write their academic papers and also by those students who simply want Assignment helpto save their time and make life easy.
107454
WEB DesigningServices in Ahmedabad

Anonymous said...

Hello! Very useful article, please also check this erp consulting companies - it is very informative

Anonymous said...

Hello! Don't know when to use semicolon in text? I understand, because it is impossible to remember all the rules, and every student wants to write a quality text! To test this question, you have created a free tool for you that helps you determine what exactly you need to use in your proposals, as well as eliminate other errors!

IndriLi said...

Catch the great post to read, thanks to which you can significantly improve the quality of your text work! This tool is very simple and easy to use, and will save you time and effort when checking text work. With the help of specialized algorithms, the tool identifies errors associated with prepositions. It can be used to check absolutely any text work. Good luck !
https://www.prepositionfinder.com/

GidLi said...

Are you still making mistakes related to the commas? Then catch the grammar check commas tool! This tool is simple and easy to use, and all you have to do is add your text to it and wait a bit! I am pleased with the results of this tool, and for this reason I can safely recommend it to you! Good luck friends!
https://www.commacheck.net/

Anonymous said...

Achieve truly impressive results in creating professional-level texts today using a free online service that will gladly help you in checking and editing the text, thereby making it of high quality. Convince yourself of the benefits of this service by reading the brief instructions on the official website. Just one click on the link and you will be satisfied with the result.
Source: https://www.commacorrector.com/

hrdnmxdvlp said...

Good day to everyone! To find out about how the CRM system works from the inside, you should talk with specialists from this sphere as well as read articles about this. I found a great resource about this, for example, you can find out about dynamics crm developer interview questions

RSM Enterprises said...

If you are taking Snovitra 20 for the first time, start with a lower dosage of 10mg and then gradually increase the dosage if needed. Do not overreach the maximum dosage of 20 mg per day.
Vardenafil 20mg(Snovitra Tablets)

RSM Multilink LLP said...

Very Nice Information!!!
Sildigra CT 7(Generic Viagra Soft Chewable)
Chat on WhatsApp with +91 92163-25377

Travel said...

"Study Tips Lab · If you are a student, this is where you can find tips and tricks only on studytipslab.com to learn how to study efficiently.
"

ahsan said...

If you’re visiting the city and want to experience it in unparalleled style and comfort, Autobots luxury cars rental is the way to go. Their premium fleet of luxury vehicles makes any trip extraordinary, whether it’s for business or pleasure. Driving one of their elite models, like a sleek sports car or a sophisticated SUV, truly elevates your travel experience.

Apparel bliss said...


Thank you for sharing this blog
Tops for Girls
Sweatshirts for Girls
hoodies for girls
frocks for girls
Tops for Girls

Jeevan Tech Digital Innovations said...

Great tutorial on email ID validation! As part of a Digital Marketing Agency in Coimbatore, we know how crucial it is to maintain a clean email list for successful campaigns. Thanks for sharing this helpful PHP sample

Popular Posts