Chinaunix首页 | 论坛 | 博客
  • 博客访问: 670634
  • 博文数量: 103
  • 博客积分: 2532
  • 博客等级: 大尉
  • 技术积分: 2039
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-26 16:07
文章分类

全部博文(103)

文章存档

2012年(38)

2011年(28)

2010年(16)

2009年(16)

2008年(5)

分类: 嵌入式

2011-11-11 16:02:15

  1. public static bool IsInteger(string s)
  2. {
  3.     string pattern = @"^\d*$";
  4.     return Regex.IsMatch(s,pattern);
  5. }
  6. ///
  7. /// 判断一个字符串是否为合法数字(0-32整数)
  8. ///
  9. /// 字符串
  10. ///
  11. public static bool IsNumber(string s)
  12. {
  13.     return IsNumber(s,32,0);
  14. }
  15. ///
  16. /// 判断一个字符串是否为合法数字(指定整数位数和小数位数)
  17. ///
  18. /// 字符串
  19. /// 整数位数
  20. /// 小数位数
  21. ///
  22. public static bool IsNumber(string s,int precision,int scale)
  23. {
  24.     if((precision == 0)&&(scale == 0))
  25.     {
  26.         return false;
  27.     }
  28.     string pattern = @"(^\d{1,"+precision+"}";
  29.     if(scale>0)
  30.     {
  31.         pattern += @"\.\d{0,"+scale+"}$)|"+pattern;
  32.     }
  33.     pattern += "$)";
  34.     return Regex.IsMatch(s,pattern);
  35. }
阅读(5802) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~