Example #1
0
        public static int StrToInt(object strValue, int defValue)
        {
            if (((strValue == null) || (strValue.ToString() == string.Empty)) || (strValue.ToString().Length > 10))
            {
                return(defValue);
            }
            string str    = strValue.ToString();
            string number = str[0].ToString();

            if (((str.Length == 10) && ValidationFun.IsNumber(number)) && (int.Parse(number) > 1))
            {
                return(defValue);
            }
            if (!((str.Length != 10) || ValidationFun.IsNumber(number)))
            {
                return(defValue);
            }
            int num = defValue;

            if ((strValue != null) && new Regex("^([-]|[0-9])[0-9]*$").IsMatch(strValue.ToString()))
            {
                num = Convert.ToInt32(strValue);
            }
            return(num);
        }
Example #2
0
 public static int SafeInt32(object objNum)
 {
     if (objNum != null)
     {
         string number = objNum.ToString();
         if (ValidationFun.IsNumber(number))
         {
             if (number.ToString().Length > 9)
             {
                 return(0x7fffffff);
             }
             return(int.Parse(number));
         }
     }
     return(0);
 }