Java regex email

后端 未结 20 2490
清歌不尽
清歌不尽 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:43

    Don't. You will never end up with a valid expression.

    For example these are all valid email addresses:

    "Abc\@def"@example.com
    "Fred Bloggs"@example.com
    "Joe\\Blow"@example.com
    "Abc@def"@example.com
    customer/department=shipping@examp­ le.com
    $A12345@example.com
    !def!xyz%abc@example.com
    _somename@example.com
    matteo(this is a comment).corti@example.com
    root@[127.0.0.1]
    

    Just to mention a few problems:

    • you don't consider the many forms of specifying a host (e.g, by the IP address)
    • you miss valid characters
    • you miss non ASCII domain names

    Before even beginning check the corresponding RFCs

提交回复
热议问题