JS:

function
 isEmail(email)
{
invalidChars 
= " /;,:{}[]|*%$#!()`<>?";
if (email == "")
{
return false;
}

for (i=0; i< invalidChars.length; i++)
{
badChar 
= invalidChars.charAt(i)
if (email.indexOf(badChar,0> -1)  {
return false;
}

}

atPos 
= email.indexOf("@",1)
if (atPos == -1)  {   return false;  }
if (email.indexOf("@", atPos+1!= -1{   return false;  }
periodPos 
= email.indexOf(".",atPos)
if(periodPos == -1{
return false;  // and at least one "." after the "@"
}

if ( atPos +2 > periodPos)  {
return false;  // and at least one character between "@" and "."
}

if ( periodPos +3 > email.length)  {   return false;  }
return true;
}


aspx: 调用:

<input id=zz><input type=button value=check onclick="if(isEmail(zz.value))alert('正确');else alert('错误')">


posted on 2006-12-18 16:35  ipusr  阅读(1470)  评论(0)    收藏  举报