asp.net 经常用到需要判断文本框是否输入的数字是小数,有无正负,几位小数,可以封装一起判断

    /// <summary>
/// 判断是否为小数点数字且带符号
/// </summary>
/// <param name="symbol">A:正负,P:正数</param>
/// <param name="message">小数点位数</param>
/// <param name="message">需检查的数字参数</param>
/// <returns>返回值</returns>
public static bool CheckIsNumberic(string type, string message,int intLength)
{
System.Text.RegularExpressions.Regex rex;
//(@"^\-?\d+(\.\d{1,2})?$") 正负
//(@"^\d+(\.\d{1,2})?$") 正数 switch (type) //A 正负数 P 正数 positive N 负数 negative
{
case "A":
rex = new System.Text.RegularExpressions.Regex(@"^\-?\d+(\.\d{1," + intLength + "})?$");
break;
case "P":
rex = new System.Text.RegularExpressions.Regex(@"^\d+(\.\d{1," + intLength + "})?$");
break;
default:
rex = new System.Text.RegularExpressions.Regex(@"^\-?\d+(\.\d{1," + intLength + "})?$");
break;
}
if (rex.IsMatch(message))
{
return true;
}
else
return false;
} //调用,比如不能超过2位小数
CheckIsNumberic("P", txtUnitPrice.Text.Trim(), )
上一篇:Error 1937.An error occurred during the installation of assembly...


下一篇:解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during ...HRESULT: 0x80070422(注意尾部的错误号)