We Recommend

Beginning VB.NET Beginning VB.NET
Visual Basic .NET is the latest version of the most widely used programming language in the world, popular with professional developers and complete beginners alike. This book will teach you Visual Basic .NET from first principles. You'll quickly and easily learn how to write Visual Basic .NET code and create attractive windows and forms for the users of your applications.


Posted By

Anthony on 09/02/08


Tagged

email validation RegularExpression


Versions (?)


Email Address Format Validation


Published in: VB.NET 


Uses a regular expression to validate a string as a validly formatted email address.

  1. ''' <summary>
  2. ''' Determines whether provided email address is properly formatted.
  3. ''' </summary>
  4. ''' <param name="s"></param>
  5. ''' <returns></returns>
  6. ''' <remarks></remarks>
  7. Private Function IsValidEmailFormat(ByVal s As String) As Boolean
  8. Dim result As Boolean = False
  9.  
  10. If Not String.IsNullOrEmpty(s) Then
  11.  
  12. '^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$
  13. Dim pattern As String = My.Settings.Email_Validation_Pattern
  14.  
  15. Dim match As RegularExpressions.Match = RegularExpressions.Regex.Match(s, pattern)
  16. result = match.Success
  17. End If
  18.  
  19. Return result
  20. End Function

Report this snippet 

You need to login to post a comment.