We prove that, for any closed semialgebraic subset W of \({\mathbb {R}}^n\) and for any positive integer p, there exists a Nash function \(f:{\mathbb {R}}^n\setminus W\longrightarrow (0, \infty )\) which is equivalent to the distance function from W and at the same time it is \(\Lambda _p\) -regular in the sense that \(|D^\alpha f(x)|\le C d(x, W)^{1- |\alpha |}\) , for each \(x\in {\mathbb {R}}^n{\setminus } W\) and each \(\alpha \in {\mathbb {N}}^n\) such that \(1\le |\alpha |\le p\) , where C is a positive constant. In particular, f is Lipschitz. Some applications of this result are given.