英文和阿拉伯字符的Android电子邮件验证 [英] Android email validation for english and arabic characters

查看:66
本文介绍了英文和阿拉伯字符的Android电子邮件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此正则表达式模式来验证电子邮件地址:

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.

这是我在项目中为android(OS)合并的正则表达式模式:

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.

推荐答案

这可能不是最好的答案,但是我可以通过添加阿拉伯语字符使其工作:

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})+

这是有关regexr的示例!(它无法正确显示阿拉伯语选择,但已被选中)

这篇关于英文和阿拉伯字符的Android电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆