if (System.Text.RegularExpressions.Regex.IsMatch(this.textBox7.Text.Trim(), "^[0-9]*$"))
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions;namespace temp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string str = textBox1.Text; Regex r = new Regex("\\d+");//验证输入框中至少输入一个数字 Match m = r.Match(str); if (m.Success) { label1.Text = "success"; } else { label1.Text = "fail"; } } } }
只要是bool型的值,都可以放到if条件中如: if (System.Text.RegularExpressions.Regex.IsMatch(inputvalue, 正则表达式))
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;namespace temp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
Regex r = new Regex("\\d+");//验证输入框中至少输入一个数字
Match m = r.Match(str);
if (m.Success)
{
label1.Text = "success";
}
else
{
label1.Text = "fail";
}
}
}
}
if (System.Text.RegularExpressions.Regex.IsMatch(inputvalue, 正则表达式))