确定输入的Email地址是否有效该用哪个函数,要在客户端检测!有结果马上结贴!

liwenqiu_2001 2004-04-02 02:40:40
如题!
...全文
39 点赞 收藏 14
写回复
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Symanteck 2004-04-02
我正在用的代码 //email可以为空
function checkemail(ssemail)
{
if (ssemail == "")
return true;
else
{
var re=/^\w+@\w+(.\w+)*$/i;
if(re.test(ssemail))
return true;
else
{
window.alert("Email的格式不正确!");
return false;
}
}
}
回复
zjwz001 2004-04-02
function checkemail(name, data, allowednull)
{
var datastr = data;
var lefttrim = datastr.search(/\S/gi);

if (lefttrim == -1) {
if (allowednull) {
return 1;
} else {
alert("请输入一个正确的E-mail地址!");
return -1;
}
}
var myRegExp = /[a-z0-9](([a-z0-9]|[_\-\.][a-z0-9])*)@([a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)((\.[a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)*)/gi;
var answerind = datastr.search(myRegExp);
var answerarr = datastr.match(myRegExp);

if (answerind == 0 && answerarr[0].length == datastr.length)
{
return 0;
}

alert("请输入一个正确的E-mail地址!");
return -1;
}

回复
zjwz001 2004-04-02
<script>
function checkstring(name,data,allowednull)
{
var datastr = data;
var lefttrim = datastr.search(/\S/gi);

if (lefttrim == -1) {
if (allowednull) {
return 1;
} else {
alert("请输入" + name + "!");
return -2;
}
}

if (datastr.search(/[<>]/gi) != -1) {
alert("" + name + "中包含非法字符<>");
return -1;
}
return 0;
}
</script>
回复
ghlfllz 2004-04-02
function isemail(email) {
var endvalue,allowstrlist;
endvalue=true;
allowstrlist="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@";
if (email.lastIndexOf("@")==-1 || email.lastIndexOf(".")==-1) {
endvalue=false;
} else if (email.indexOf("@",email.indexOf("@")+1)!=-1 || email.indexOf(".",email.indexOf("@"))==-1) {
endvalue=false;
} else if (email.substr(0,1)=="@" || email.substr(0,1)=="." || email.substr(email.length-1,1)=="@" || email.substr(email.length-1,1)==".") {
endvalue=false;
}
for (i=0;i<email.length;i++) {
if (allowstrlist.indexOf(email.substr(i,1))==-1) {
endvalue=false;
break;
}
}
return(endvalue);
}
回复
2004-04-02
我自己正在使用的函数,直接调用即可
'**************************************************
'函数名:IsValidEmail
'作 用:检查Email地址合法性
'参 数:email ----要检查的Email地址
'返回值:True ----Email地址合法
' False ----Email地址不合法
'**************************************************
function IsValidEmail(email)
dim names, name, i, c
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if
end function
回复
liuyingzi 2004-04-02
if(document.fkinfo.fkemail.value.length!=0)
{
if (document.fkinfo.fkemail.value.charAt(0)=="." ||
document.fkinfo.fkemail.value.charAt(0)=="@"||
document.fkinfo.fkemail.value.indexOf('@', 0) == -1 ||
document.fkinfo.fkemail.value.indexOf('.', 0) == -1 ||
document.fkinfo.fkemail.value.lastIndexOf("@")==document.fkinfo.fkemail.value.length-1 ||
document.fkinfo.fkemail.value.lastIndexOf(".")==document.fkinfo.fkemail.value.length-1)
{
alert("Email地址格式不正确!");
document.fkinfo.fkemail.focus();
return false;
}
}
else
{
alert("Email不能为空!");
document.fkinfo.fkemail.focus();
return false;
}
回复
tddw 2004-04-02
已经写好,请自己测试!:

<form method="POST" action="--WEBBOT-SELF--" name="form1">
<p><input type="text" name="T1" size="20"><input type="button" onclick="tt(this.form.T1.value)" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p>
</form>

<script language="javascript">
<!--
function tt(b){
var a=/\w+@{1}\w+\.\w+/
if(!a.test(b)){
alert("您的email地址不正确!")
}
}
-->
</script>
回复
iwebet 2004-04-02
呵呵都比我写的好啊 重哪扒的啊 好眼熟啊
回复
xzq686 2004-04-02
<script language="javascript">

function ismail(mail)
{
return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}
alert(ismail("aaa@bbb.ccc"));
alert(ismail("aaa$bbb.ccc"));
alert(ismail("aaa@bbb"));
</script>
回复
iwebet 2004-04-02
<script language=vbscript>
function emals()
emlstr=表单名.项目名.value
if instr(emlstr,"@")>0 then
el=split(emlstr,"@")
if instr(el(0),".")=0 then
......'包所有的非法字符判断一次
'返回成功
else
Messagebox("E-Mail不合法")
end if
end if
end Function
</script>
回复
xzq686 2004-04-02
试试下面的函数!
<script language="javascript1.2">
     <!--
     function verifyAddress(obj)
     {
      var email = obj.email.value;
      var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
      flag = pattern.test(email);
      if(flag)
      {
       alert(“Your email address is correct!”);
       return true;
      }
      else
       {
        alert(“Please try again!”);
        return false;
        }
      }
     -->
    </script>
回复
pizixt 2004-04-02
function isEmail(email){
var pattern=/^[\w.-]+@([\w-]+\.)+[a-z]{2,3}$/i;
if(email.length>0){
if(pattern.test(email)){
return true;
}else{
alert('Email输入错误,请检查\n\r');
return false;
}
}else{
alert('Email不能为空\n\r');
return false;
}
}
回复
tddw 2004-04-02
请稍等,
我正帮你编写。
回复
iwebet 2004-04-02
不只是一个函数 你可以用JS写个函数来判断 地址是否有效
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告