using System.Text.RegularExpressions;string strTemp = "0.123"; Regex r = new Regex("((-?)|(+?))\d*.\d*"); if (r.IsMatch(strTemp)) { //符合 }
lovefootball(蟑螂) 检测“-456,789.0”为无效
using System.Text.RegularExpressions;string strTemp = "0.123"; Regex r = new Regex(@"^[+-]?\d*(,\d{3})*(\.\d+)?$"); if (r.IsMatch(strTemp)) { //符合 }
lovefootball(蟑螂) 检测“.123”也无效
using System.Text.RegularExpressions;string strTemp = "0.123"; Regex r = new Regex(@"^[+-]?\d*(,\d{3})*(\.\d+)?$"); if (r.IsMatch(strTemp)) { //符合 }我的可以吗?
{
decimal a=Convert.ToDecimal("YourString");
//correct
}
catch
{
//incorrect
}
using System.Text.RegularExpressions;public bool IsNumber(String strNumber)
{
Regex objNotNumberPattern=new Regex("[^0-9.-]");
Regex objTwoDotPattern=new Regex("[0-9]*[.][0-9]*[.][0-9]*");
Regex objTwoMinusPattern=new Regex("[0-9]*[-][0-9]*[-][0-9]*");
String strValidRealPattern="^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
String strValidIntegerPattern="^([-]|[0-9])[0-9]*$";
Regex objNumberPattern =new Regex("(" + strValidRealPattern +")|(" + strValidIntegerPattern + ")");return !objNotNumberPattern.IsMatch(strNumber) &&
!objTwoDotPattern.IsMatch(strNumber) &&
!objTwoMinusPattern.IsMatch(strNumber) &&
objNumberPattern.IsMatch(strNumber);
}
Regex r = new Regex("((-?)|(+?))\d*.\d*");
if (r.IsMatch(strTemp))
{
//符合
}
Regex r = new Regex(@"^[+-]?\d*(,\d{3})*(\.\d+)?$");
if (r.IsMatch(strTemp))
{
//符合
}
Regex r = new Regex(@"^[+-]?\d*(,\d{3})*(\.\d+)?$");
if (r.IsMatch(strTemp))
{
//符合
}我的可以吗?