Subscribe For Free Updates!

We'll not spam mate! We promise.

Aug 19, 2013

PHP - Validate Email Id


PHP - Validate Email Id :

 Here i will explain how to validate email id in php. This is very use full to validate email id in server side. php is used in server so we can validate email id in server side. if you want to validate email id in client side then you can use JavaScript, jquery etc...

 The below example will show you how to validate email id in PHP

Example :
<?php

$mailId = "xxx@gmail.com"; // Valid email
$conditions = '/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([comco.in])+$/';
if (preg_match($conditions, $mailId))
{
echo "Valid Mail Id";
}
else
{
echo "Invalid Mail Id";
}

?&gt;





 In the above example "$mailId" having the email id given by user. and "$conditions" having conditions for validate given email id. here i used "preg_match()" predefined php function. this function return boolean value. if the match occurred then it will return true otherwise false.

 The above example print "Valid Mail Id". Here the variable "$conditions" have "com","co","in" conditions only, so it will allow these extension mail id only. and it will validate all allowed special characters only.

 if A$mailId="xxx@gmailo.comnm" then the output is "Invalid Mail Id".

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment