首页 > Web开发 > 详细

Asp.net 判断输入的字符串是不是数字

时间:2014-02-10 16:43:02      阅读:368      评论:0      收藏:0      [点我收藏+]

     /// <summary>

    /// 判断输入的字符串是不是数字,不是返回True,否则返回False

    /// </summary>

    /// <param name="text"></param>

    /// <returns></returns>

    public static bool IsNum(string text) 

     {

         for (int i = 0; i < text.Length; i++)  

         {

             if (!Char.IsNumber(text, i)) 

             { 

                 return true//输入的不是数字  

             }

         }

         return false//否则是数字

     }

自己又做了一个延伸,判断输入的字符串全部是汉字,没有数字

/// <summary>

    /// 判断输入的字符串全是字符不包括数字,不是返回false,否则返回true 20100728

    /// </summary>

    /// <param name="text"></param>

    /// <returns></returns>

    public static bool IsChar(string text)  

  {

        int count = 0;

        for (int i = 0; i < text.Length; i++)

        {

            if (!Char.IsNumber(text, i)) //不是数字

            {

                count++;

           }

        }

        if (count == text.Length)

        {

            return true//输入全是字符,不包括数字

        }

        else

        {

            return false//否则是数字

        }

    }

Asp.net 判断输入的字符串是不是数字

原文:http://www.cnblogs.com/shizhongyi/p/3542519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!