ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

IsEmail

Extend string with boolean test for a valid email address

Source

Module MyExtensions
    <System.Runtime.CompilerServices.Extension()> _
    Public Function IsEmail(ByVal text As String) As Boolean
        Dim Expression As New System.Text.RegularExpressions.Regex("\S+@\S+\.\S+", System.Text.RegularExpressions.RegexOptions.Compiled)
        If Expression.IsMatch(text) Then
            Return True
        Else
            Return False
        End If
    End Function
End Module

Example

if textbox1.text.IsEmail then 
 sendmail(message)
end if

Author: Jim Tripp

Submitted on: 31 mei 2010

Language: VB

Type: System.string

Views: 3844