title: How can I convert this short PHP function into JavaScript?
body: <p>How can I replicate this PHP code into JavaScript?  It takes a number like 2-9999 (serial number) and converts it into a NUMBER ... 2-999 would be a different value when converted.</p>
  <pre><code>function esn_to_num($esn)
  {
  
      if (($tmp = explode('-', $esn))) {
  
          if (sizeof($tmp) == 2
              &amp;&amp; my_isnum($tmp[0])
              &amp;&amp; my_isnum($tmp[1])
          ) {
              $esn = (($tmp[0] &lt;&lt; 23) | $tmp[1]);
          } else {
              $esn = -1;
          }
      } else {
          $esn = -1;
      }
  
      return $esn;
  }
  </code></pre>
  <p>I added a dependency function below:</p>
  <pre><code>// dependency function
      /*****************************************************************************
      * CHECKS IF A STRING REPRESENTS A NUMBER
      ******************************************************************************/
      function my_isnum($str, $negative=false, $decimal=false)
      {
          $has_decimal = false;
          $len = strlen($str);
          if ($len &gt; 0) {
              $valid = true;
              for ($i=0; $valid &amp;&amp; $i&lt;$len; $i++) {
                  if (!($str[$i] &gt;= '0' &amp;&amp; $str[$i] &lt;= '9')) {
                      if ($str[$i] == '-') {
                          if (!$negative || $i != 0) {
                              $valid = false;
                          }
                      } else if ($str[$i] == '.') {
                          if (!$decimal || $has_decimal) {
                              $valid = false;
                          }
                      } else {
                          $valid = false;
                      }
                  }
              }
          } else {
              $valid = false;
          }
          return $valid;
      }
  </code></pre>