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
{
}
}
本文介绍了一个用于检查字符串是否为数值型的实用函数。通过正则表达式匹配的方式判断输入的字符串是否符合特定的数字格式,包括整数和最多三位小数的浮点数。该方法适用于需要对用户输入进行验证的场景。
1177

被折叠的 条评论
为什么被折叠?



