Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
0
0
DE
I have a written a code to validate email id as,

Function EmailAddressCheck(ByVal emailAddress As String) As Boolean

Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"

Dim emailAddressMatch As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(emailAddress, pattern)
If emailAddressMatch.Success Then
EmailAddressCheck = True
Else
EmailAddressCheck = False
End If

End Function


I need to validate like after '.' only 3 characters should be present.

Can anyone help me?
 
If you want only 3 characters, use {3} after that part of the pattern.
 
Can you please tell me where to place the {3} and i also need the condition that before @ there can be 1 character also.
 
sorry, the required condition is the number of characters after .(dot) should not be greater than 3 and the number of characters before @ should be minimun 1
 
While not the answer to your issue, I wanted to pose the question:

Are you sure you really want this check??

I am not a regular expression expert, but it seems to me if you are validating on only three characters in the last part of the domain name, you will run into issues.

Examples:
xxxxxxxx@tampabay.rr.com (my primary email domain name)
xxxx@somewhere.fm (media domain names - like radio stations)
xxxx@somewhere.info (email attached to an informational site)
xxxx@somewhere.xx (the xx domain at the end here can be replaced by emails from various countries - .ru, .nz)

I only pose this question because you may not be aware of the fact that a domain name no longer HAS to end with a three character extension. Just like the of an http website address is not always true anymore. As the internet continues to grow (and especially the use of IPv6), the concepts of .com, .org, .biz, etc are quickly expanding.

If you limit your input to only a three part .com-like extension, you may be creating problems for people who do not have this "semi-standard" convention in their email address.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top