none
Allowing the ";" in a oRegEx pattern? RRS feed

  • Question

  • Hi

    Public Function ValidateEmail(ByVal sEmail As Variant) As Boolean

    peter@fors.com is ok but peter@fors.com ; peter@home.se is not. The “;” is not accepted-

    My pattern, today, is like the one below. How do I change the pattern?

    oRegEx.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"


    Cheers // Peter Forss Stockholm


    Monday, November 18, 2019 7:20 AM

Answers

  • Hi Imb

    Thanks for helping. The string below is right for me:

    ^(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)(\s*;\s*|\s*$))*$


    Cheers // Peter Forss Stockholm

    • Marked as answer by ForssPeterNova Monday, November 18, 2019 4:54 PM
    Monday, November 18, 2019 1:44 PM

All replies

  • peter@fors.com is ok but peter@fors.com ; peter@home.se is not. The “;” is not accepted-

    Hi Peter,

    Some time ago there was also a thread about valid email-adresses. I thought Daniel published a complicated RegEx for the analysis.

    The problem I had with that is, how can the developper add new functionality to the string - as you experience now - and hoe does the user know what is wrong with an emailadress, especially for people that are word-blind or dislectic.

    So I made my own "analysis" program, and I display all the needed corrections in a (dynamical) form. I handle also the multiple adresses. It is easily done by splitting the complete string using ";" as separator, and loop through the successive array elements.

    You can use it also in this way while using your Original RegEx.

    As an example a picture of the form. I realize now that I have not yet the signal for a "=" character. What also could be added is the email-address itself, so  the user can modify it. Next addition could be that when the user corrects a mistake, the corresponding error message will turn green, and when all lines are green the emailaddress is "correct", at least according to the syntax and the used rules. Only with a "correct" address one can exit the underlying control "Email"

    Imb.

    Monday, November 18, 2019 8:54 AM
  • Hi Imb

    Thanks for helping. The string below is right for me:

    ^(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)(\s*;\s*|\s*$))*$


    Cheers // Peter Forss Stockholm

    • Marked as answer by ForssPeterNova Monday, November 18, 2019 4:54 PM
    Monday, November 18, 2019 1:44 PM
  • It's because ; isn't valid for an e-mail address.

    It is used as a separator by certain program, but isn't part of the email address itself. Personally, I'd split my string based on the separator and test each element (email address) individually.  Then you could at least identify which email address was incorrect.


    Daniel Pineault, 2010-2019 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Monday, November 18, 2019 3:59 PM
  • Thanks for helping. The string below is right for me:

    ^(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)(\s*;\s*|\s*$))*$

    Hi Peter,

    Of course, no need to change it.

    But what I also said in my answer is that you can use the Split function to separate concatenated email adrress, and check each address separately.

    Imb.

    Monday, November 18, 2019 4:37 PM
  • Hi Daniel

    I have tested my latest pattern and it works good (at least until now)

    The email server on my provider accepts ; semi colon and , comma as an email adress separator.


    Cheers // Peter Forss Stockholm


    Monday, November 18, 2019 4:39 PM