第一种方法 使用Try Catch(不推荐)
private bool IsNumberic(
string oText)
{
try
{
int var1=Convert.ToInt32 (oText);
return true;
}
catch
{
return false;
}
}
第二种方法 正则表达式(推荐)
public static bool IsNumeric(
string value)
{
return Regex.IsMatch(
value,
@"^[+-]?/d*[.]?/d*$");
}
public static bool IsInt(
string value)
{
return Regex.IsMatch(
value,
@"^[+-]?/d*$");
}
public static bool IsUnsign(
string value)
{
return Regex.IsMatch(
value,
@"^/d*[.]?/d*$");
}
第三种方法 遍历(显得很弱)
转载请注明原文地址: https://ju.6miu.com/read-1310650.html