 <p>Try this:</p> <pre><code>^\$?(\d+(?:\.\d*)?|\.\d+)$ </code></pre> <p>It will match:</p> <pre><code>^\$? # an optional $ at the begin (\d+ # one or more digits (?:\.\d*)? # followed by an optional decimal part |\.\d+ # or just decimal places without any leading digits )$ </code></pre>