<!--  checkEmail.js  validateEmailList.php  written by and Copyright © 2009 Joe Golembieski, SoftMoon WebWare

		This program is free software: you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation, either version 3 of the License, or
		(at your option) any later version.

		This program is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.

		You should have received a copy of the GNU General Public License
		along with this program.  If not, see <http://www.gnu.org/licenses/>

//    tab spacing=2  editor width=120  auto-word-wrap=no

-->
<script type="text/javascript">
function checkEmail(eadd)  {
  eadd=eadd.replace(/^[\s]+/, "");  eadd=eadd.replace(/[\s]+$/, "");
  if (eadd=="")  {alert('Please enter an eMail address');  return false;}
  var literal="[\x2D^!#$%&'*+/=?0-9A-Z_`a-z{|}~]+";
  var quoted='"[\x20-\x7F]+"';
  var word="("+literal+"|"+quoted+")";
  var domn="([-0-9A-Z_a-z]+|"+quoted+")";
  var emailAdd=word+"([.]"+word+")*@("+domn+"[.])+[a-zA-Z]{2,6}";
  var litName="[\x2D\x20^!#$%&'*+/=?0-9A-Z_`a-z{|}~]+";
  var quoName='"[\x00-\x09\x0E-\x21\u0023-\uFFFF]+"[\x20\t]*';
  var emailFormat="("+emailAdd+"|("+litName+"|"+quoName+")<"+emailAdd+">)";
  var emailList=emailFormat+"(,[\x20\t\n]*"+emailFormat+")*";
  var emailValid=new RegExp("^"+emailList+"$");
  if (emailValid.test(eadd))  return true;
  else  {
    alert('The eMail address you entered has an invalid format.  Please check it and try again');
    return false;  }  }
</script>
<?php
Function validateEmailList($given)  {

  $literal="[-!#$%&'*+=?0-9A-Z^_`a-z{|}~\/]+";
  $quoted='"[\x20\x21\x23-\x7F]+"';
  $word="(?:".$literal."|".$quoted.")";
  $domain="(?:[-0-9A-Z_a-z]+|".$quoted.")";
  $emailAdd="(".$word."(?:[.]".$word.")*@(?:".$domain."[.])+[a-zA-Z]{2,6})";
  $litName="[- !#$%&'*+=?0-9A-Z^_`a-z{|}~\/]+";
  $quoName='"[\x01-\x09\x0E-\x21\x23-\xFF]+"[\x20\t]*';
  $emailRecipient="(?:".$emailAdd."|(?:".$litName."|".$quoName.")<".$emailAdd.">)";
  $emailList=$emailRecipient.'(?:,[\x20\t\n]*'.$emailRecipient.')*';

  // echo strlen($emailList)," characters long<br />\n",$emailList,"<br />\n";

  if (preg_match('/^'.$emailList.'$/', $given)==FALSE)  return FALSE;

  $list=array();
  do  { preg_match('/^'.$emailRecipient.'/', $given, $validated);
    $list[]=array($validated[0], ($validated[1]!="") ? $validated[1] : $validated[2]);
    $given=trim(substr($given, strlen($validated[0])+1));  }
  while (strlen($given)>0);
  return $list;  }
?>