How to allow only a certain number of words?
<p>Say I have a Scanner, and a user adds two words to that scanner.</p>

<p>There should be no space before the first word.</p>

<p>Only one space between the two words.</p>

<p>And no space after the second word.</p>

<p>i.e. </p>

<pre><code>'hello world' is correct
</code></pre>

<p>but</p>

<pre><code>'hello world bye' 
' hello world' 
'hello word ' 
'hello  world'
</code></pre>

<p>are all incorrect.</p>

<p>I've tried to use regex, but with no success. </p>

<p>EDIT: Only letters a to z allowed (uppercase and lower)</p>
