Email Address Format Validation


/ Published in: VB.NET
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.