同桌上课用手指进去了好爽_欧美丰满熟妇xxⅹⅹ性大i_成人av天天日天天拍拍_猛男gay帅男gay男男同志_欧美va天堂在线观看_人妻无码av中文系列三里桃花_亚欧免费无码在线观看_久久久精品国产亚洲av水_日韩在线免费看污污污_2021无码专区人妻系列日韩

首頁 優(yōu)化推廣 在C#.Net中判斷輸入的字串是否是數(shù)字的方法

在C#.Net中判斷輸入的字串是否是數(shù)字的方法

來源: | 時(shí)間:2013/8/22 10:39:12 |

在Textbox的輸入中﹐我們常常需要控制輸入的類型﹐比如說只能輸入數(shù)字﹐當(dāng)然實(shí)現(xiàn)的方法很多﹐我總結(jié)了一下我做過的一些項(xiàng)目﹐我常會(huì)使用以下這三種﹕
1﹑使用Try...Catch
        private static bool IsNumeric(string itemValue,int intFLag)
        {
            try
            {
                int i = Convert.ToInt32(itemValue);
                return true;
             }
            catch
            {
                return false;
             }
         }

2﹑使用正則表達(dá)式
using System.Text.RegularExpressions;
        
         private static bool IsNumeric(string itemValue)
        {
            return (IsRegEx("^(-?[0-9]×[.]×[0-9]{0,3})$", itemValue));
         }

        private static bool IsRegEx(string regExValue, string itemValue)
        {
            try
            {
                 Regex regex = new System.Text.RegularExpressions.Regex(regExValue);
                if (regex.IsMatch(itemValue)) return true;
                else                          return false;
             }
            catch (Exception )
            {
                return false;
             }
            finally
            {
             }
         }

3﹑判斷輸入的keyCode
      

服務(wù)熱線

153 8323 9821

功能和特性

價(jià)格和優(yōu)惠

網(wǎng)站和維護(hù)

推廣和優(yōu)化

微信服務(wù)號(hào)