Java regex email

后端 未结 20 2563
清歌不尽
清歌不尽 2020-11-22 13:09

First of all, I know that using regex for email is not recommended but I gotta test this out.

I have this regex:

\\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]         


        
20条回答
  •  鱼传尺愫
    2020-11-22 13:33

    If you want to allow non-latain characters, this one works quite well for me.

    "^[\\p{L}\\p{N}\\._%+-]+@[\\p{L}\\p{N}\\.\\-]+\\.[\\p{L}]{2,}$"
    

    It does not allow IP's after the @ but most valid email in the from of xxx@xxx.TDL could be validated with it. \p{L} validates UTF-Letters and \p{N} validates UTF-Numbers. You can check this doc for more information.

提交回复
热议问题