public bool CheckMoney(string money) //验证输入字符串是否是数字(包括小数)
{
bool flag = true;
int count = 0;
if (money.Length == 0)
{
flag = false;
MessageBox.Show("请输入金额!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
char[] x = money.ToCharArray();
for (int i = 0; i < money.Length; i++)
{
if (!char.IsNumber(x[i]) && x[i] != '.')
{
flag = false; break;
}
if (x[i] == '.')
{
count++;
if (i == 0 || i == money.Length - 1) flag = false;
}
}
if (count > 1) flag = false;
if (!flag) MessageBox.Show("输入金额的格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return flag;
}