1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Dim MatchEmail As Matcher = Regex.Matcher

Discussion in 'Android Questions' started by ElliotHC, Aug 13, 2019.

  1. ElliotHC

    ElliotHC Active Member Licensed User

    I'm trying to do some email entry code and I have no idea how this works, does anyone know?

    Code:
    Dim MatchEmail As Matcher = Regex.Matcher("^(?i)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])$", EmailAddress)
    I'm trying to get it to allow the newer email domains like .systems for example.

    What does what where in that massive long string of gibberish?
     
  2. emexes

    emexes Well-Known Member Licensed User

    The ultimate arbiter of what constitues a valid email address is the email provider, and you will never get a regex that matches that. Case in point: all the filters that ruled that the final domain segment must be 2-3 chacters long, then 2-4 when .info and .name appeared, then... dang it...

    What you can test for is that an email address is plausible. NO FALSE REJECTIONS. So basically any character except @ for the name, and any character but @./ in the domain name segments, only one @ in the address, and at least one . in the domain name. You're helping people to type in their email address, not validating that it is an actual working address. The only way to validate that is to send it an email and see what happens.
     
    ElliotHC likes this.
  3. emexes

    emexes Well-Known Member Licensed User

    Now that I'm back on a real keyboard with a real screen...

    This guru (seriously - best site ever about regular expressions):

    https://www.regular-expressions.info/email.html

    says use this (where I've made the two changes discussed in the fourth paragraph so that it works immediately for you):
    Code:
    ^\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b$
    and you can try it out here (and/or get a step-by-step explanation of how it matches an email address):

    https://regex101.com/

    As for that gem of a regex from your original post, which neither you nor I understand, well... the best I can say is: it's very impressive. And if you decide to stick with it, then: good luck!

    :)
     
    ElliotHC, JordiCP and Erel like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice