问题
I am currently using this regular expression pattern to validate email addresses:
android.util.Patterns.EMAIL_ADDRESS.matcher(emailAddress).matches();
It doesn't work with Arabic characters. I need it to work with both English and Arabic characters.
This is the regex pattern I have incorporate for android (OS) in my project:
public static final Pattern EMAIL_ADDRESS
= Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
")+"
);
I am not regex expert. I could use some help figuring out how to support both.
回答1:
This may not be the best answer, but I was able to get it to work by adding the aribic characters:
[\u0621-\u064A\u0660-\u0669a-zA-Z0-9\+\.\_\%\-\+]{1,256}\@[\u0621-\u064A\u0660-\u0669a-zA-Z0-9][\u0621-\u064A\u0660-\u0669a-zA-Z0-9\-]{0,64}(\.[\u0621-\u064A\u0660-\u0669a-zA-Z0-9][\u0621-\u064A\u0660-\u0669a-zA-Z0-9\-]{0,25})+
Here's an example on regexr! (it doesn't display Arabic selection properly, but it is selected)
来源:https://stackoverflow.com/questions/43150333/android-email-validation-for-english-and-arabic-characters