Validating a form field with several emails

This might help:

What do you want to happen if any email is invalid - throw error/message or ignore that one and continue?

if you want to stop if any are invalid, something like this might work (I have not specifically tested it!):

function formatter_checkemails($emailList){ 
    $emails = explode(',', $emailList);    
    foreach ($emails as $email) {
        $email = trim($email);
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return false;
        }
    }

    return true;
}
1 Like