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 testreg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void Regex_string(string Str_text,string Str_y,string Str_n,string Str_reg)
{
if (Regex.IsMatch(Str_text, Str_reg))
{
MessageBox.Show(Str_y);
}
else
{
MessageBox.Show(Str_n);
}
}
private void button1_Click(object sender, EventArgs e)
{
Regex_string(textBox1.Text.Trim(), "有汉字", "没汉字", @"[^/x00-/xff]");
}
private void button2_Click(object sender, EventArgs e)
{
Regex_string(textBox2.Text.Trim(), "是", "否", @"[/u4e00-/u9fa5]");
}
private void button3_Click(object sender, EventArgs e)
{
Regex_string(textBox3.Text.Trim(), "不是数字", "是数字", @"[^0-9]");
}
private void textBox4_KeyDown(object sender, KeyEventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
//用正则替换掉非数字的字符
Regex regex =new Regex(@"[^0-9]");
string Str_tb4 = textBox4.Text.Trim();
Str_tb4 = regex.Replace(Str_tb4, "");
textBox4.Text = Str_tb4;
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
//用正则替换掉非汉字的字符
Regex regex = new Regex(@"[/x00-/xff]");
string Str_tb4 = textBox5.Text.Trim();
Str_tb4 = regex.Replace(Str_tb4, "");
textBox5.Text = Str_tb4;
}
}
}