codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.72k stars 409 forks source link

Validator standard Email regex doesn't work for '-' #1692

Open gerbenk opened 8 years ago

gerbenk commented 8 years ago

One of my customers tried to register with an email with a dash '-' and this is invalid according to the validater

RE r = new RE("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
System.out.println("Match: " + r.match("g-k@gmail.com"));

When I slightly change the regex to the following, it does work, so I think the problem is in the regex engine.

RE r = new RE("^[a-zA-Z0-9-.!#$%&'*+/=?^_`{|}~]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
System.out.println("Match: " + r.match("g-k@gmail.com"));
codenameone commented 8 years ago

Can you clarify a bit what changed between the first and the second RE statement?

gerbenk commented 8 years ago

The minus sign was moved from the end of the first [] to the middle. But it should have worked already, so I guess the problem is in the regex engine.