formregexvalidation.cs

来自「csharp课本的源代码」· CS 代码 · 共 53 行

CS
53
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RegexExample1
{
    public partial class FormRegexValidation : Form
    {
        public FormRegexValidation()
        {
            InitializeComponent();
        }

        private void buttonValidation_Click(object sender, EventArgs e)
        {
            //System.Text.RegularExpressions.Regex r = 
            //    new System.Text.RegularExpressions.Regex(textBoxValidateString.Text);
            //if (r.IsMatch(textBoxValidatedString.Text) == true)
            //{
            //    textBoxIsMatch.Text = "有匹配项";
            //}
            //else
            //{
            //    textBoxIsMatch.Text = "没有匹配项";
            //}
            System.Text.RegularExpressions.Regex r =
       new System.Text.RegularExpressions.Regex(textBoxValidateString.Text);
            if (r.IsMatch(textBoxValidatedString.Text) == true)
            {
                textBoxIsMatch.Text = "有匹配项";
            }
            else
            {
                textBoxIsMatch.Text = "没有匹配项";
            }

        }

        private void textBoxValidatedString_Enter(object sender, EventArgs e)
        {
            textBoxIsMatch.Clear();
        }

        private void textBoxValidateString_Enter(object sender, EventArgs e)
        {
            textBoxIsMatch.Clear();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?