Android email validation for english and arabic characters

放肆的年华 提交于 2020-01-17 08:30:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!