开发者

Regular expression which accepts multiple email addresses seperated by comma in java

In my project I give email address to send the mail in a text box. I can give either a single email address or a multiple email address separated by commas. Is there any regular expression for this situation. I used the following code and its check for single email address only.

public static boolean isEmailValid(String email){  

            boolean isValid = false;  
        String expression = "^[\\w\\.开发者_StackOverflow-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";  
        CharSequence inputStr = email;  

        Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);  
        Matcher matcher = pattern.matcher(inputStr);  
        if(matcher.matches()){  
        isValid = true;  
        }  
        return isValid;  
        } 


  1. Split the input by a delimiter in your case ','.
  2. Check each email if its a valid format.
  3. Show appropriate message (email 1 is valid , email 2 is not valid , email 3 is not valid etc etc)


You can split your email-var on a ",", and check for each emailaddress you got :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜