/// <summary>
/// 验证浮点数
/// 这个表达式认为“123.”或“123.123.123”不是有效的浮点数,
/// 认为“.123”或“123.123”或“123”是正确的浮点数。
/// </summary>
/// <param name="strNum"></param>
/// <returns></returns>
public bool checkFloatAndInt(string strNum)
{
string reg = "^(//d*//.)?//d+$";
Regex regex = new Regex(reg);
if (!regex.IsMatch(strNum))
return false;
decimal num = Convert.ToDecimal(strNum);
if (num < 0 || num > 24000000)
return false;
return true;
}
/// <summary>
/// 验证整数
/// </summary>
/// <param name="strNum"></param>
/// <param name="len"></param>
/// <returns></returns>
public bool CheckInt(string strNum,int len)
{
string reg = "^//d{0,"+len+"}$";
Regex regex = new Regex(reg);
if (!regex.IsMatch(strNum))
return false;
else
return true;
}
/// <summary>
/// 验证日期 YYYY-MM-DD
/// </summary>
/// <param name="strDate"></param>
/// <returns></returns>
public bool CheckDate(string strDate)
{
string reg = "^(//d{4})-(//d{1,2})-(//d{1,2})$";
Regex regex = new Regex(reg);
if (!regex.IsMatch(textBox1.Text.Trim()))
{
return false;
}
string[] arr = strDate.Split('-');
int year = Convert.ToInt32(arr[0]);
int month = Convert.ToInt32(arr[1]);
int date = Convert.ToInt32(arr[2]);
if (year < 1900 || year > 3000)
return false;
if (month <= 0 || month > 12)
return false;
if (date <= 0 || date > 31)
return false;
return true;
}