gistlib
index.tsfunction isFilename(str: string): boolean { // Regular expression to check if the string is a valid filename const regex = /^[a-zA-Z0-9\s_@\-^!#$%&+={}\[\]]+\.(jpg|jpeg|png|gif|pdf|docx)$/i; return regex.test(str); } // Example const filename = "example.jpg"; if (isFilename(filename)) { console.log("Valid filename"); } else { console.log("Invalid filename"); } 385 chars15 lines
function isFilename(str: string): boolean { // Regular expression to check if the string is a valid filename const regex = /^[a-zA-Z0-9\s_@\-^!#$%&+={}\[\]]+\.(jpg|jpeg|png|gif|pdf|docx)$/i; return regex.test(str); } // Example const filename = "example.jpg"; if (isFilename(filename)) { console.log("Valid filename"); } else { console.log("Invalid filename"); }
gistlibby LogSnag