Let $X = \mathrm{Spec}(R)$ be an affine variety, $f$ a rational function on $X$ such that $f_{|U}$ is regular, where $U\subset X$ is an open subset of the form $U = \mathrm{Spec}(R_{g})$ where $g\in R$ and $R_{g}$ is the localization of $R$ at $g$. Then $f_{|U}\in R_g$.
May we then conclude that $f$ is regular on $X$?
No, you may not. For $R = ℚ[T]$, $f = 1/T$ is rational on $X = \mathbb A_ℚ^1$ and regular on $D(T) = \operatorname{Spec} R_T$, but $f$ is not regular on $X$. Setting $g = T$ and $U = D(T)$, this yields a counerexample. You can modify this counterexample to $f = (T - 1)/T$ if you want $f$ to vanish somewhere on $U$.