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;
}
- Split the input by a delimiter in your case ','.
- Check each email if its a valid format.
- 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 :)
精彩评论