//方法一: public bool IsNameValid(string name) { if (name.Length > 20) { return false; } foreach (char c in name) { if (!Char.IsLetterOrDigit(c) && !Char.IsWhiteSpace(c) && c != '_') { return false; } } return true; }

//方法二: public bool IsNameValid(string name) { if (name.Length > 20) { return false; }

foreach (char c in name)
{
    if (!(Char.IsLetterOrDigit(c) || c == '_' || Char.IsWhiteSpace(c)))
    {
        return false;
    }
}
return true;

}

C# 验证文件夹名称格式和系统命名规范:长度限制、字符限制 (无正则表达式)

原文地址: https://www.cveoy.top/t/topic/lkav 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录