Android Question Dim MatchEmail As Matcher = Regex.Matcher

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?

B4X:
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?
 

emexes

Expert
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.
 
Upvote 0

emexes

Expert
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):
B4X:
^\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!

:)
 
Upvote 0
Top