Validate: limiting number of selections in a multiple select

Validate: limiting number of selections in a multiple select

Hello,

I've got Jquery Validate running on my form locally and have all form element validations working correctly except this one. I've been searching the forum but can't come up with a solution. 

I have a select box set to multiple. The list of options is about 15-20 items but users can only choose 5. How can I check that they have not selected more than 5 and message them if so?

  1. <select id="my_list" name="my_list" class="form-control" multiple="multiple">
  2. <option value="1">home</option>
  3. <option value="2">vacation</option>
  4. <option value="3">school</option>
  5. <option value="4">outside</option>
  6. <option value="5">inside</option>
  7. <option value="6">car</option>
  8. <option value="7">bicycle</option>
  9. <option value="8">work</option>
  10. </select>