To validate Email ID is quite common but when it comes to validate a multiple email Id from textarea input then you will be facing many bugs. I Have solved this issue in my task and i hope
it will be useful for you..
client may ask to enter the Email Id in this format:
For this output we can use javascript or PHP coding. so i have used Php coding for this one,lets see how can we extract the result by separating comma’s and enter carraige.
it will be useful for you..
client may ask to enter the Email Id in this format:
ex1:(To type in horizontal wise)
test@sdf.com,rest@test.com,rest@sdf.com
ex2:(To type in vertical order)
For this output we can use javascript or PHP coding. so i have used Php coding for this one,lets see how can we extract the result by separating comma’s and enter carraige.
Code:
//To explode the submitted value when you press Enter button
$arrLines = explode(”\n”,$_POST['email']);
//Separated values are stored in $value
foreach($arrLines as $key=>$value){
//Now we are Looking for comma operator , if they have specified in field
$arrEmail = explode(”,”,$value);
//Separated values are stored in $value1
foreach($arrEmail as $key1=>$value1){
//Here i am checking whether the user as entered any Null values
if(trim($value1)!=”){
//Regular Expression used to check the Email is valid or Not
if(!eregi(’^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$’, trim($value1))){
//Assigning invalid email Id to varaible
$invalidemailId = trim($invalidemailId.$value1).”<br>”;
//Printing the email Id which is Not Valid.
$erroremail=’Mail as Not Sent For Following Email ID,Please Enter Valid Email ID<br> ‘.$invalidemailId;
}
//To send the mail to list
else{
$from=’inforeply@bharat.com’;
$to = $value1;
$subject = ‘Birthday Reminders for August’;
$message =file_get_contents(’mailers/bmp-mailer.html’);
$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From:’ .$from . “\r\n”;
mail($to, $subject, $message, $headers);
}
}
No comments:
Post a Comment