static int StrToInt(string str, int defValue)
{
if (str == null)
return defValue;
if (str.Length > 0 && str.Length <= 11 && Regex.IsMatch(str, @"^[-]?[0-9]*$"))
{
if ((str.Length < 10) || (str.Length == 10 && str[0] == '1') || (str.Length == 11 && str[0] == '-' && str[1] == '1'))
{
return Convert.ToInt32(str);
}
}
return defValue;
}
阅读(2634) | 评论(0) | 转发(0) |