Is there a law or regulation that requires a specific type of pipe to be used for the tub spout to connect to ? Main question is can CPVC be used instead of galvanized or some other metal pipe ?
I don't think there are any professionals installing galvanized steel pipe anymore. CPVC is too flexible and/or likely to snap off under pressure. The inside diameter is also smaller than copper.
For a solid installation, stub out a piece of copper or thread in a brass nipple.
If this is a tub/shower set up,virtually every manufacurer speficies you may NOT use CPVC or PEX for the spout connections. The reduced inside diameter reduces flow rate, and will cause leakage from the shower head while using the tub.
If the inspector is good, codes generally require fixtures to be installed per code, and per the manufacturers' instructions...none accept plastic for a tub/shower to the spout.
I've been meaning to put a video that I took of plastic piping to a tub spout. It was PEX in that case and it was forcing water out of the shower head.