Javascript test for identifier

Date: 2021-12-29
const reIdentifier = /^[0-9a-z][0-9a-z_-]*$/i;
const isIdentifier = (value) => {
    if (typeof value !== "string" && typeof value !== "number")
        return false;
    return reIdentifier.test(String(value).trim());
};

console.log("=======================");
console.log(isIdentifier(""));
console.log(isIdentifier(":test"));
console.log(isIdentifier(new Date()));
console.log(isIdentifier("123.32"));
console.log("=======================");
console.log(isIdentifier("a"));
console.log(isIdentifier("2"));
console.log(isIdentifier("328d5f42-e03e-4bfc-a3cd-b4e399f2be29"));
58540cookie-checkJavascript test for identifier