javascript
function isValidFilename(filename) {
const forbiddenChars = /[<>:"/\\|?*]/;
if (forbiddenChars.test(filename)) {
return false;
}
if (filename.endsWith(' ') || filename.endsWith('.')) {
return false;
}
const reservedNames = ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9'];
const nameWithoutExtension = filename.split('.')[0];
if (reservedNames.includes(nameWithoutExtension.toUpperCase())) {
return false;
}
return true;
}