How can I determine whether the email address format is correct?

Source: Internet
Author: User

Method 1:

<%

Function IsValidEmail (Email)

ValidFlag = False

If (Email <> "") And (InStr (1, Email, "@")> 0) And (InStr (1, Email, ".")> 0) Then

AtCount = 0

SpecialFlag = False

For atLoop = 1 To Len (Email)

AtChr = Mid (Email, atLoop, 1)

If atChr = "@" Then atCount = atCount + 1

If (atChr> = Chr (32) And (atChr <= Chr (44) Then SpecialFlag = True

If (atChr = Chr (47) Or (atChr = Chr (96) Or (atChr> = Chr (123) Then SpecialFlag = True

If (atChr> = Chr (58) And (atChr <= Chr (63) Then SpecialFlag = True

If (atChr> = Chr (91) And (atChr <= Chr (94) Then SpecialFlag = True

Next

If (atCount = 1) And (SpecialFlag = False) Then

BadFlag = False

TAry1 = Split (Email ,"@")

UserName = tAry1 (0)

DomainName = tAry1 (1)

If (UserName = "") Or (DomainName = "") Then BadFlag = True

If Mid (DomainName, 1, 1) = "." then BadFlag = True

If Mid (DomainName, Len (DomainName), 1) = "." then BadFlag = True

ValidFlag = True

'The format is correct and true is returned.

End If

End If

If BadFlag = True Then ValidFlag = False

'If the format is incorrect, False is returned.

IsValidEmail = ValidFlag

End Function

%>

Method 2:

<%
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)-faster Rev (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
%>

The third method is to use the following function for judgment. It checks whether the email address contains "@" and whether "." Is after:

Function isEmail (pInString)

LAt = False
LDot = false

For x = 2 to len (pInstring)-1
If mid (pInString, x, 1) = "@" then lAt = True
If mid (pInString, x, 1) = "." and lAt = True then lDot = True
Next

If lAt = True and lDot = True then
IsEmail = True
Else
IsEmail = False
End if
End function

[1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.