Abstract Let f : X → ℝ {f:X\rightarrow\mathbb{R}} be a function defined on a connected nonsingular real algebraic set X in ℝ n {\mathbb{R}^{n}} . We prove that regularity of f can be detected by controlling the restrictions of f to either algebraic curves or algebraic surfaces in X. If dim X ≥ 2 {\operatorname{dim}X\geq 2} and k is a positive integer, then f is a regular function whenever the restriction f | C {f|_{C}} is a regular function for every algebraic curve C in X that is a 𝒞 k {\mathcal{C}^{k}} submanifold homeomorphic to the unit circle and is either nonsingular or has precisely one singularity. Moreover, in the latter case, the singularity of C is equivalent to the plane curve singularity defined by the equation x p = y q {x^{p}=y^{q}} for some primes p < q {p<q} . If dim X ≥ 3 {\operatorname{dim}X\geq 3} , then f is a regular function whenever the restriction f | S {f|_{S}} is a regular function for every nonsingular algebraic surface S in X that is homeomorphic to the unit 2-sphere. We also have suitable versions of these results for X not necessarily connected.