asp检查email是否合法可用的函数

2010年07月24日 23:48 by:佚名

asp检查email是否合法可用的函数,经过测试可用,放在这里以备以后查用。

  1.  function IsValidEmail(email)
  2.  dim names, name, i, c
  3.  IsValidEmail = true
  4.  names = Split(email, "@")
  5.  if UBound(names) <> 1 then
  6.     IsValidEmail = false
  7.     exit function
  8.  end if
  9.  for each name in names
  10.   if Len(name) <= 0 then
  11.    IsValidEmail = false
  12.       exit function
  13.   end if
  14.   for i = 1 to Len(name)
  15.       c = Lcase(Mid(name, i, 1))
  16.    if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
  17.          IsValidEmail = false
  18.          exit function
  19.        end if
  20.     next
  21.     if Left(name, 1) = "." or Right(name, 1) = "." then
  22.        IsValidEmail = false
  23.        exit function
  24.     end if
  25.  next
  26.  if InStr(names(1), ".") <= 0 then
  27.   IsValidEmail = false
  28.     exit function
  29.  end if
  30.  i = Len(names(1)) - InStrRev(names(1), ".")
  31.  if i <> 2 and i <> 3 then
  32.     IsValidEmail = false
  33.     exit function
  34.  end if
  35.  if InStr(email, "..") > 0 then
  36.     IsValidEmail = false
  37.  end if
  38. end function
标签:email合法