使用正则表达式验证两位小数
发布时间:2020-12-14 06:12:58 所属栏目:百科 来源:网络整理
导读:实现效果: 知识运用: ? 代码实现: private void button1_Click(object sender,EventArgs e) { if (IsValidate(textBox1.Text.ToString())) MessageBox.Show("验证通过","提示:"); else MessageBox.Show("验证失败","提示:"); } //方法定义 public bool
实现效果: 知识运用: ? 代码实现: 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}$"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |