3/29日小作业,上一个任务的拓展,对三个输入框的检测。

要求:对上一次的作业进行拓展,同时检测三个输入文本。

对每个输入框的有效等价类与无效等价类与上次的相同。

测试用例如下:

编号 输入1 输入2 输入3 预期输出 实际输出
test1 123456 abcdef abc123 √√√ 符合
test2 !@#$%   1234567 ××× 符合
test3 abc 测试 123!@# √×× 符合

*注test2输入2为无输入。

屏幕截图如下

主要代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions; 

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String text1 = textBox1.Text;
            String text2 = textBox2.Text;
            String text3 = textBox3.Text;

            label4.Text = check_Text(text1, 0);
            label5.Text = check_Text(text2, 0);
            label6.Text = check_Text(text3, 0);
        }

        public String check_Text(String text, int mode)
        {
            return check_Text(text) == 0 ? "" : "×";
        }

        public int check_Text(String text)
        {
            Regex regex = new Regex(@"^[A-Za-z0-9]+$");

            int result = -1;
            if (text.Length > 6 || text.Length < 1)
            {
                result = 1;
            }
            else if (!regex.IsMatch(text))
            {
                result = 2;
            }
            else
            {
                result = 0;
            }
            return result;
        }
    }
}
View Code

全部文件如下(vs2013)

https://files.cnblogs.com/files/limiting/3InputVersion.rar

原文地址:https://www.cnblogs.com/limiting/p/4376428.html