The IsValidEmail capacity checks for a substantial email, IsValidEmail returns True if the email location is a legitimate email, IsValidEmail returns false if the email location isn't appropriate grammar. The code is very much remarked and ought to clarify what is occurring .

This code checks for @ and a . period sign and additionally just worthy characters. i.e. on the off chance that a client have entered # or $ sign in his/her email address then this capacity will return false.

view sourceprint?

01.

'*******************************************************

02.

'* MYCPLUS Sample Code - http://www.mycplus.com ; *

03.

'*

04.

'* This code is made accessible as a support of our *

05.

'* guests and is given entirely to the *

06.

'* motivation behind outline. *

07.

'*

08.

'* Please guide all request to saqib at mycplus.com *

09.

'*******************************************************

10.

11.

Capacity IsValidEmail(emailAddress)

12.

'Announce variables

13.

Faint ValidEmail, emailParts, iLoopCounter, emailChar, acceptableChars

14.

ValidEmail = True 'set the default result to True

15.

'acceptableChars are the characters that we will permit in our email

16.

acceptableChars="abcdefghijklmnopqrstuvwxyz.- _@"

17.

'utilize the Split capacity to make a cluster with the @ as the separator

18.

'so if your email was test@tester.com the email would be split into a cluster

19.

'with the first cluster component holding "test" and the second "tester.com"

20.

emailParts = Split(emailAddress, "@")

21.

'check to ensure that there is just 1 @ and that there are 2 sections

22.

'keep in mind clusters are zero based

23.

'Utilizing the UBound capacity will give back the most astounding component in the cluster

24.

'So in the event that it's a legitimate email the UBound capacity will return 1, i.e. 0 begin

25.

In the event that UBound(emailParts) <> 1 Then

26.

ValidEmail = false

27.

Else

28.

'Check the length of every piece of the email address

29.

'to begin with part can be only one character, second part must be atleast 4

30.

In the event that Len(emailParts(0))<1 OR Len(emailParts(1))<4 Then

31.

ValidEmail = false

32.

End If

33.

'check first character on the left part isn't a "." utilizing Left capacity

34.

In the event that Left(emailParts(0), 1)="." Then

35.

ValidEmail = false

36.

End If

37.

'check the last and second character from right part utilizing Right capacity

38.

In the event that Right(emailParts(1), 1) = "." OR Right(emailParts(1), 2) = "." Then

39.

ValidEmail = false

40.

End If

41.

'watch that there is a . in the second some portion of the email address - .com

42.

On the off chance that InStr(emailParts(1), ".") <= 0 Then

43.

ValidEmail = false

44.

End If

45.

'watch that there shouldn't be a _ in the second a portion of the email address

46.

On the off chance that InStr(emailParts(1), "_") >0 Then

47.

ValidEmail = false

48.

End If

49.

End If

50.

'circle through every character of email

51.

For iLoopCounter = 1 to Len(emailAddress)

52.

'Use Lcase and Mid capacities, Mid capacity used to give back every individual character

53.

'in the email, and after that Lcase changes over it into lowercase

54.

emailChar = Lcase(Mid(emailAddress, iLoopCounter, 1))

55.

'Check if the emailAddress characters are adequate

56.

On the off chance that InStr(acceptableChars, emailChar) = 0 and Not IsNumeric(emailChar) Then

57.

ValidEmail = false

58.

End if

59.

Next

60.

'check if there is 2 . consecutively

61.

On the off chance that InStr(emailAddress, "..") > 0 Then

62.

ValidEmail=false

63.

End If

64.

'check if there is @. consecutively

65.

On the off chance that InStr(emailAddress, "@.") > 0 Then

66.

ValidEmail=false

67.

End If

68.

IsValidEmail=ValidEmail

69.

End capacity
 
Top