Constraining fundamental constant variations from ultralight dark matter with pulsar timing arrays