1、前端JS代码
/* receiver-----接收人 */
function foreachEmail(receiver){
var str="";
var email ="";
if(receiver!="" && receiver.indexOf(";")>0)
{
var arremail=receiver.split(";");
for(var i=0;i <arremail.length;i++)
{
if(arremail[i].replace(/s+/g,"").search(/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/)==-1)
{
str=str+arremail[i]+"格式错误!
";
}else{
if(i > 0){
if(arremail[i] != arremail[i-1]){
email = email+";"+arremail[i];
}
}else{
email = arremail[i];
}
}
}
receiver = email;
}else{
if(receiver.replace(/s+/g,"").search(/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/)==-1)
{
str=receiver+"格式错误!
";
}
}
if(str!="")
{
$("#alertmsg").html(str);
return false;
}
return receiver;
}
//当文本框失去焦点时,判断是否输入重复的邮箱输入的话就不显示重复的邮箱
$("#receiver").blur(function(){
var email = foreachEmail($("#receiver").val().replace(/(^s*)|(s*$)/g,''));
if(email == false){
$("#receiver").val("");
}else{
$("#receiver").val(email);
}
});
function sendEmail(){
receiver = $("#receiver").val();
receiver = foreachEmail(receiver);
if(receiver == false){
return false;
}
$.ajax({
... //此处略去发送的代码
});
}
2、后台PHP代码
可以用explode()方法把取得的邮件字符串分离,代码就不赘述了!!!