Multilingual email address validation with jQuery and RegEx

前端 未结 2 845
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 08:22

I have some jQuery and RegEx code that works great validating email addresses...as long as the address is based on simple Latin characters. However, when we plu

相关标签:
2条回答
  • 2021-01-27 08:29

    There is a very simple method to apply all you RegEx logic(that one can apply easily in English) for any Language using Unicode.

    For matching a range of Unicode Characters like all Alphabets [A-Za-z] we can use

    [\u0041-\u005A] where \u0041 is Hex-Code for A and \u005A is Hex Code for Z

    'matchCAPS leTTer'.match(/[\u0041-\u005A]+/g)
    //output ["CAPS", "TT"]
    

    In the same way we can use other Unicode characters or their equivalent Hex-Code according to their Hexadecimal Order (eg: \u0A10 to \u0A1F) provided by unicode.org

    Try: [电-触]

    It will match all characters between 电 and 触 if provided by unicode.org in this order

    I don't know chinese :)

    0 讨论(0)
  • 2021-01-27 08:40

    Take a look at the XRegExp library. It is a Javascript library that implements a Unicode-aware regex engine, including character classes like \p{Letter} that can be used to match letters outside the usual ASCII range.

    0 讨论(0)
提交回复
热议问题