检查命名的规范性,防止输入危险字符
using System.Text.RegularExpressions;
public static bool CheckString(string inputString, int maxLength)
{
bool success=true;
// StringBuilder retVal = new StringBuilder(); ///构造临时字符串数组
if ((inputString != null) && (inputString != String.Empty))
{
inputString = inputString.Trim(); ///清空字符串两段的空白符号
if (inputString.Length > maxLength)
{ ///设置字符串的长度
inputString = inputString.Substring(0, maxLength);
}
for (int i = 0; i < inputString.Length; i++)
{
switch(inputString[i])
{
///去除危险字符串(\ ,/,:,*,?,",<,>,| )
case '*':case'|':case '<':case '>':case '/':case '\\':case ':': case '?':case '"':
success=false; break;
default:;break;
}
}
}
return success;
}
public static bool CheckString(string inputString, int maxLength)
{
bool success=true;
// StringBuilder retVal = new StringBuilder(); ///构造临时字符串数组
if ((inputString != null) && (inputString != String.Empty))
{
inputString = inputString.Trim(); ///清空字符串两段的空白符号
if (inputString.Length > maxLength)
{ ///设置字符串的长度
inputString = inputString.Substring(0, maxLength);
}
for (int i = 0; i < inputString.Length; i++)
{
switch(inputString[i])
{
///去除危险字符串(\ ,/,:,*,?,",<,>,| )
case '*':case'|':case '<':case '>':case '/':case '\\':case ':': case '?':case '"':
success=false; break;
default:;break;
}
}
}
return success;
}