title: Is this the correct approach to do input validation with floating point values?
body: <p>After spending a good amount of time researching input validation, I combined a few ideas and came up with this:</p>
  
  <p><strong>Function to check a string for a valid <code>double</code>...</strong></p>
  
  <pre><code>bool isDouble(double&amp; destination, string&amp; source)
  { // 64 bit
    bool goodValue = false;
  
    if (!source.empty()) {
      errno = 0;
      char *garbage = nullptr;
      destination = strtod(source.c_str(), &amp;garbage);
  
      if (*garbage == '\0' &amp;&amp; errno != ERANGE)
        goodValue = true;
    }
  
    return goodValue;
  }
  </code></pre>
  
  <p><strong>Function to check a string for a valid 32 bit <code>integer</code>...</strong></p>
  
  <pre><code>bool isLong(long&amp; destination, string&amp; source)
  { // 32 bit (base 10)
    const short BASE = 10;
    bool goodValue = false;
  
    if (!source.empty()) {
      errno = 0;
      char* garbage = nullptr;
      destination = strtol(source.c_str(), &amp;garbage, BASE);
  
      if (*garbage == '\0' &amp;&amp; errno != ERANGE)
        goodValue = true;
    }
  
    return goodValue;
  }
  </code></pre>
  
  <p><strong>Sample Implementation</strong></p>
  
  <pre><code>using namespace std;
  
  int main() {
    string buffer;
    double value;
  
    cout &lt;&lt; "Enter a value: ";
    getline(cin, buffer, '\n');
  
    if (isDouble(value, buffer))
      cout &lt;&lt; "Value: " &lt;&lt; value &lt;&lt; endl;
    else
      cout &lt;&lt; "ERROR: Invalid input\n";
  
    return 0;
  }
  </code></pre>
  
  <p>Can anyone comment on if I am overlooking anything with this approach?</p>