C# 无正则表达式验证文件夹名称:长度限制与字符规范
// 使用 C# 代码 public static bool VerifyFolderName(string folderName) { // 判断长度是否超过 20 个字节 if (folderName.Length > 20) { return false; }
// 判断是否包含特殊字符
for (int i = 0; i < folderName.Length; i++)
{
// 如果包含特殊字符,则返回 false
if (!(Char.IsLetter(folderName[i]) ||
Char.IsDigit(folderName[i]) ||
folderName[i] == '_' ||
folderName[i] == '-' ||
folderName[i] == '.'))
{
return false;
}
}
return true;
}
原文地址: https://www.cveoy.top/t/topic/lkaW 著作权归作者所有。请勿转载和采集!