asp.net 判断字符串是否是数字的,int的,整型的

  1. #region 判断字符串是否是数字的   
  2.   
  3.   
  4. /// <summary>   
  5. /// 判断是否是数字   
  6. /// </summary>   
  7. /// <param name="str">字符串</param>   
  8. /// <returns>bool</returns>   
  9. public bool IsNumeric(string str)   
  10. {   
  11.     if (str == null || str.Length == 0)   
  12.         return false;   
  13.     System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();   
  14.     byte[] bytestr = ascii.GetBytes(str);   
  15.     foreach (byte c in bytestr)   
  16.     {   
  17.         if (c < 48 || c > 57)   
  18.         {   
  19.             return false;   
  20.         }   
  21.     }   
  22.     return true;   
  23. }  
posted on 2009-08-25 14:17  米高佐敦  阅读(299)  评论(0编辑  收藏  举报