Windows Phone Developers

Showing posts with label .NET exception handling to detect incorrect email addresses. Show all posts
Showing posts with label .NET exception handling to detect incorrect email addresses. Show all posts

Tuesday, May 6, 2008

Validate eMail Addresses using VB.NET Function

Detect errors in email addresses using .NET exception handling

There are n-number of ways to detect errors in email addresses; some use regular expressions to do that. The same has been built as a check in ASP.NET validation controls.

The following function uses the Try-Catch exception handling by assigning the address to the mail message. If the format of the email address is found to be wrong, then the function returns false. A simple one; please post your comments on the way it worksJ

Function Detect_MailAddress_Errors(ByVal sMailAdd As String) As Boolean


Try

Dim oMailMsg As New MailMessage

oMailMsg.To.Add(sMailAdd)

Return True

'Format Exceptions

Catch exFormat As FormatException

'MsgBox("Format Error")

Return False

' General Exceptions

Catch ex As Exception

End Try

End Function

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon