设为首页 收藏本站 English

当前位置: 海南体育网 >> 欧冠

验证输入的是否数字的几种方法覆盖

发布时间:2021-09-06 02:12:14

方法一: static bool IsNumeric(string str)

{

if (str==null || ngth==0)

return false;

foreach(char c in str)

{

if (!Number(c))

{

return false;

}

}

return true;

}

方法二:

private bool IsNumeric(string s)

private bool IsNumeric(string s)

{

char ch0 = \'0\';

char ch9 = \'9\';

for(int i=0; i ngth; i++)

{

if ((s[i] ch0 || s[i] ch9))

{

xt=\"此处应输入整数且非负!\";

return false;

}

}

return true;

}

方法三:

-分众传媒第一季度资本支出为110万美元。 static bool IsNumeric (string str)

{

gex reg1

= new gex(@\"^[-]?\\d+[.]?\\d*$\");

return Match(str);

}

方法四:(可扩展)

public static bool IsConvert(string Expression,Type DataType)

{

switch()

{

case \"Double\":

try

{

rse(Expression);

return true;

}

catch

{

return false;

}

case \"DateTime\":

try

{

rse(Expression);

return true;

}

catch

{

return false;

}

default:

return true;

}

}

C#验证输入的是否数字的方法

其实用正则表达式也可以

static bool IsNumeric(string str)

{

if (str==null || ngth==0)

return false;

foreach(char c in str)

{

if (!Number(c))

{

return false;

}

}

return true;

}

正则表达的写法是:

static bool IsNumeric(string str)

{

gex reg1

= new gex(@\"^[-]?\\d+[.]?\\d*$\");

return Match(str);

}

查看本文来源

米诺地尔酊能生发吗
兰州治疗宫颈糜烂费用
南昌治男科医院
友情链接