判断Email地址是否正确的几个函数(asp/php/javascript)
程序员文章站
2022-05-24 22:32:40
用js判断 复制代码 代码如下: function is_email( str ){ p = /^([\w\.-]+)@([a-za-z0-9-]+)(\.[a-za-z\...
用js判断
function is_email( str ){
p = /^([\w\.-]+)@([a-za-z0-9-]+)(\.[a-za-z\.]+)$/;
if(str.search(p) == -1){
return false;
}else{
return true;
}
}
用php判断
function is_email($email){
$pattern="/^([\w\.-]+)@([a-za-z0-9-]+)(\.[a-za-z\.]+)$/i";//包含字母、数字、下划线_和点.的名字的email
if(preg_match($pattern,$email,$matches)){
return true;
}else{
return false;
}
}
用asp判断
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
复制代码 代码如下:
function is_email( str ){
p = /^([\w\.-]+)@([a-za-z0-9-]+)(\.[a-za-z\.]+)$/;
if(str.search(p) == -1){
return false;
}else{
return true;
}
}
用php判断
复制代码 代码如下:
function is_email($email){
$pattern="/^([\w\.-]+)@([a-za-z0-9-]+)(\.[a-za-z\.]+)$/i";//包含字母、数字、下划线_和点.的名字的email
if(preg_match($pattern,$email,$matches)){
return true;
}else{
return false;
}
}
用asp判断
复制代码 代码如下:
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