February 17th, 2009

ASP常用自定义函数--IsValidEmail()

Learning, by 木公.
'=============================================================
'检查Email是否合法
'=============================================================
Public 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

'说明: 当出现恶意提交时,返回False
'示例: If IsValidEmail("lackyking#gmail.com")= False Then Response.Write "False"

相关日志

Back Top

Responses to “ASP常用自定义函数--IsValidEmail()”

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Back Top