Verify user input is 5 digit number
<p>I am working on a project where the user is prompted to enter a zip code. I need to verify it is a five digit number (I don't need to verify it is an actual zip code).</p>

<p>Here is a portion of my code.</p>

<pre><code>string userInput;
cout &lt;&lt; "Zip Code&gt; ";
getline(cin, userInput, '\n');


while (stoi(userInput)&lt;10000 || stoi(userInput) &gt; 99999){
    cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "You must enter a valid zip code. Please try again." &lt;&lt; endl;
    cout &lt;&lt; "Zip Code&gt;" &lt;&lt; endl;
    getline(cin, userInput, '\n');
}

PropertyRec.setZipCode(stoi(userInput));
</code></pre>

<p>This works fine unless the zip code starts with a zero.  If it does, the validation is no good and the initial zero never saves to the variable once the input string is converted to an integer.</p>

<p>Should I leave the zip code as a string when saving to the database?  If so, how can I verify there are exactly 5 characters and each character is numeric?</p>