locked
Regex for Email address with space between ID and @ RRS feed

  • Question

  • User1536465747 posted

    As mentioned in the subject, I need a regex that can catch the following email addresses: 

    myemailid @ yahoo.com
    
    myemailid @yahoo.com
    
    myemailid@ yahoo.com

    Meaning, I am aware that these email addresses are not valid but I need such regex to catch entering invalid email address in the biography field. 

    Thank you 

    Thursday, February 14, 2019 8:52 PM

Answers

  • User-943250815 posted

    Looks you getting a mail address in string.
    Try this ([a-zA-Z0-9._-]+\s?@\s?[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)

    \s? before/after @ means "Any whitespace Zero or One time"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 14, 2019 10:06 PM

All replies

  • User-943250815 posted

    Give a try to EmailValidation, is it available on Nuget.
    Very simple and cover many other cases

    Dim MailOK as string = nothing
    If EmailValidator.Validate(<mailaddress>) = true Then
      MailOK = "Valid"
    else
      MailOk = "Not Valid"
    endif

    Thursday, February 14, 2019 9:20 PM
  • User1536465747 posted

    I am afraid it's not what I am looking for.

    Rather I need to catch all invalid email instances and strip them from biography string. 

    The point is that the contact info is forbidden there. 

    Thank you

    Thursday, February 14, 2019 9:29 PM
  • User-943250815 posted

    Looks you getting a mail address in string.
    Try this ([a-zA-Z0-9._-]+\s?@\s?[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)

    \s? before/after @ means "Any whitespace Zero or One time"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 14, 2019 10:06 PM