yes its most definitely building code. GA had an amendment until this year that only required them within 10' of a bedroom door. now they have to be inside and out of the door. some towns adopt NFPA Life Safety Code, which is a little more stringent than the building code; cannot be within 3ft of forced air ducts, 3ft of bathroom door with shower or tub, not less than 4 and not more than 12 inches away from ceiling if mounted on the wall, and it requires you to mount it in the highest ceiling (if a tray ceiling is in the room).
----- i think they have to be 3' from the edge of a ceiling fan too, btw.