Java regex email

后端 未结 20 2028
清歌不尽
清歌不尽 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:47
    String emailRegex = "[a-zA-Z0-9_.]+@[a-zA-Z0-9]+.[a-zA-Z]{2,3}[.] {0,1}[a-zA-Z]+";
    Pattern.matches(emailRegex,"You_Input_Mail_Id");
    

    This is the regex to match valid email addresses.

    0 讨论(0)
  • 2020-11-22 13:49

    you can use a simple regular expression for validating email id,

    public boolean validateEmail(String email){
      return Pattern.matches("[_a-zA-Z1-9]+(\\.[A-Za-z0-9]*)*@[A-Za-z0-9]+\\.[A-Za-z0-9]+(\\.[A-Za-z0-9]*)*", email)
    }
    

    Description :

    1. [_a-zA-Z1-9]+ - it will accept all A-Z,a-z, 0-9 and _ (+ mean it must be occur)
    2. (\.[A-Za-z0-9]) - it's optional which will accept . and A-Z, a-z, 0-9( * mean its optional)
    3. @[A-Za-z0-9]+ - it wil accept @ and A-Z,a-z,0-9
    4. \.[A-Za-z0-9]+ - its for . and A-Z,a-z,0-9
    5. (\.[A-Za-z0-9]) - it occur, . but its optional
    0 讨论(0)
提交回复
热议问题