For residences, IRC 2006, M1507.3 requires a bathroom or toilet room to have "Mechanical exhaust capacity of 50cfm intermittent or 20cfm continuous." IRC sets no requirement for how this is implemented, only that the capacity must be there. Same switch, separate switch, humidistat, timer, etc- all OK by IRC.

Commercial is different. IMC 2006 400.3 requires commercial bathrooms in dorms, hotels, etc, to have 35cfm ventilation/person. (Continuous is implied.) As 0 people are in the bathroom when the lights are off and 0cfm required, the fan can be tied into the light switch. I'm not familiar enough with IMC to know any other subtleties of the code, or what specifically applies to restrooms in stores or offices.