作者:熊孝琳_506 | 来源:互联网 | 2023-10-12 18:24
本文由编程笔记#小编为大家整理,主要介绍了使用正则表达式验证两位小数相关的知识,希望对你有一定的参考价值。
实现效果:

知识运用:

代码实现:
private void button1_Click(object sender, EventArgs e)
{
if (IsValidate(textBox1.Text.ToString()))
MessageBox.Show("验证通过","提示:");
else
MessageBox.Show("验证失败", "提示:");
}
//方法定义
public bool IsValidate(string str_decimal) {
return System.Text.RegularExpressions.
Regex.IsMatch(str_decimal,@"^[0-9]+.[0-9]{2}$");
}