Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ***********************************************************************
- ' Author : Elektro
- ' Modified : 26-April-2017
- ' ***********************************************************************
- #Region " Public Members Summary "
- #Region " Functions "
- ' ValidateMail(String) As Boolean
- ' ValidateMail(MailAddress) As Boolean
- #End Region
- #End Region
- #Region " Option Statements "
- Option Strict On
- Option Explicit On
- Option Infer Off
- #End Region
- #Region " Imports "
- Imports System.Net.Mail
- 'Imports Elektro.Core.Types
- #End Region
- #Region " Mail Util "
- Namespace Tools
- Partial Public NotInheritable Class MailUtil ': Inherits AestheticObject
- #Region " Public Methods "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Validates a mail address.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim isValid As Boolean = ValidateMail("Address@Gmail.com")
- ''' Dim isValid As Boolean = ValidateMail("mailto:Address@Gmail.com")
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="address">
- ''' The mail address.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' <see langword="True"/> if the mail address is valid, <see langword="False"/> otherwise.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shared Function ValidateMail(ByVal address As String) As Boolean
- If Not address.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase) Then
- address = address.Insert(0, "mailto:")
- End If
- If Not Uri.IsWellFormedUriString(address, UriKind.Absolute) Then
- Return False
- End If
- Dim result As Uri = Nothing
- If Uri.TryCreate(address, UriKind.Absolute, result) Then
- Return (result.Scheme = Uri.UriSchemeMailto)
- Else
- Return False
- End If
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Validates a mail address.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim isValid As Boolean = ValidateMail(New MailAddress("Address@Gmail.com"))
- ''' Dim isValid As Boolean = ValidateMail(New MailAddress("mailto:Address@Gmail.com"))
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="address">
- ''' The mail address.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' <see langword="True"/> if the mail address is valid, <see langword="False"/> otherwise.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shared Function ValidateMail(ByVal address As MailAddress) As Boolean
- Return MailUtil.ValidateMail(address.Address)
- End Function
- #End Region
- End Class
- End Namespace
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement