3/18小作业,简单的非法输入检测与测试

要求:输入允许1到6个英文字符或数字,按OK结束。

有效等价类为 长度1-6,字符A-Z,a-z,0-9

无效等价类为 长度0,7,字符除以上外的其它字符

 

测试用例如下

编号输入预期结果结果
test1Aa3456OK!符合
test2@12测试ilegal input!符合
test3 length wrong!符合
test41234567length wrong!符合

*注:test3为无输入。

屏幕截图如下

 

主要代码如下

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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Regex regex = new Regex(@"^[A-Za-z0-9]+$");
            String text = textBox1.Text;
            String result;
            if (text.Length > 6 || text.Length < 1)
            {
                result="length wrong!";
            }
            else if (!regex.IsMatch(text))
            {
                result="ilegal input!";
            }
            else
            {
                result="OK!";
            }

            label2.Text = result;
        }
    }
}
View Code

全部文件如下(vs2013)

http://files.cnblogs.com/files/limiting/WindowsFormsApplication3.rar

转载于:https://www.cnblogs.com/limiting/p/4349932.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值