Limit number of multiple choice selections

I have a multiple choice field with 7 selections and the user can select multiple selections however I want to limit the total number to 5. Does anyone have a suggestion on how to accomplish this or the code? Thank you.