use ^ and $ to match the start and end of your string

^[0-9]{6}$
^[0-9]{6}\.[0-9]{3}$


Reference: http://www.regular-expressions.info/anchors.html

Also, as noted by Mikael Svenson, you can use the word boundary \b if you are searching for this pattern in a larger chunk of text.

Reference: http://www.regular-expressions.info/wordboundaries.html

You could also write both those regexes in one shot

^\d{6}(\.\d{3})?$


Regular Expression to Match String Exactly?
If I give a finite region of $\mathbb{R}^{2}$ and place $k$ circles of radius $r(k)$ uniformly at random inside, are there any known results for the probability that the circles do not overlap? Equivalently, I want the probability that the area covered by the circles is $k\pi r(k)^{2}$.
