People who stalk or harass others can now face up to five years in prison under new pattern-of-behaviour laws.