-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module1.bas
53 lines (51 loc) · 1.65 KB
/
Module1.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Function IsEmailValid(strEmail)
Dim strArray As Variant
Dim strItem As Variant
Dim i As Long, c As String, blnIsItValid As Boolean
blnIsItValid = True
Dim pos%
pos = InStr(strEmail, "@")
If pos = 0 OR InStr(pos + 1, strEmail, "@") <> 0 Then IsEmailValid = False: Exit Function
ReDim strArray(1 To 2)
strArray(1) = Left(strEmail, pos - 1)
strArray(2) = Right(strEmail, Len(strEmail) - pos)
For Each strItem In strArray
If Len(strItem) <= 0 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
For i = 1 To Len(strItem)
c = LCase(Mid(strItem, i, 1))
If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
Next i
If Left(strItem, 1) = "." Or Right(strItem, 1) = "." Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
Next strItem
If InStr(strArray(2), ".") <= 0 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
' i = Len(strArray(2)) - InStrRev(strArray(2), ".")
' If i <> 2 And i <> 4 Then
' blnIsItValid = False
' IsEmailValid = blnIsItValid
' Exit Function
' End If
If InStr(strEmail, "..") > 0 Then
blnIsItValid = False
IsEmailValid = blnIsItValid
Exit Function
End If
IsEmailValid = blnIsItValid
End Function