'How can I convert this short PHP function into JavaScript? [closed]

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.

function esn_to_num($esn)
{

    if (($tmp = explode('-', $esn))) {

        if (sizeof($tmp) == 2
            && my_isnum($tmp[0])
            && my_isnum($tmp[1])
        ) {
            $esn = (($tmp[0] << 23) | $tmp[1]);
        } else {
            $esn = -1;
        }
    } else {
        $esn = -1;
    }

    return $esn;
}

I added a dependency function below:

// 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 > 0) {
            $valid = true;
            for ($i=0; $valid && $i<$len; $i++) {
                if (!($str[$i] >= '0' && $str[$i] <= '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;
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source