Limiting checkbox selections

Hi guys,

Ive been stuck with this problem for some time.
Hope you guys can help me out.

I have 45 check boxes. I figured out how to get the info on what items the user has selected using arrays.

Heres my problem:

On click of the submit button, how can i trap and inform the user that he can only check exactly 4 boxes. no more no less.

Sounds simple but i cant figure it out.
Anybody?

Anybody guys?

Ok let me rephrase, probably easier…

Is there a way to count how many of the 45 checkboxes have a check mark (selected) on them?