How do I limit or require the number of tags in a taxonomy reference field?
The module field_validation has an option for Number of selections which could be what you need without custom coding. For 7, there's a full release and for 8, there's an alpha.