Can you check the `id` first? the regex doesn't need to test if the id is defined.

    if (!id && isYouTubeRegex.test(urladdr)) {