Java regex email

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

    Thanks to @Jason Buberel's answer, I think lowercase letters must be validated by the RegEX. So the following is correct:

    [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}
    

    Now, both developer961@mail.com and DEV961@yahoo.COM are valid!
    Note that \. should be \\. to escape . and have \. itself. Since, . is a meaningful character in java RegEX means all characters.

提交回复
热议问题