メールアドレスチェック

気休め程度に。
全角と半角対応


function SubmitForm()
{
 c=document.form1.mail.value;
 if(MailCheck( c,1 ) == 1)
 {
  alert('メールアドレスの形式が正しくありません');
  document.form1.mail.focus();
  return;
 }
 document.form1.submit();

} 
 
/*===============================================================

★メアドチェックモジュール

引数
str: 文字列
mode:1 全角OK
mode:2 全角NG

返り値
1:メールアドレス正しくない
0:メールアドレス正しい

===============================================================*/

function MailCheck( str,mode ){

 if (mode==1){
  if(str.match(/..*[@|@]..*[\.|.]..*/i)){
   return (0);
  }
 }else{
  if(str.match(/..*@..*\...*/i)){
   return (0);
  }
 }
 
 return (1);
}
 


MailCheck( チェック対象文字列 , モード )
モードは「1」だと全角もOK 「2」だと半角のみ