您的位置:首页 > 其它

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

2015-03-29 21:35 127 查看
要求:对上一次的作业进行拓展,同时检测三个输入文本。

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

测试用例如下:

编号输入1输入2输入3预期输出实际输出
test1123456abcdefabc123√√√符合
test2!@#$%1234567×××符合
test3abc测试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)
http://files.cnblogs.com/files/limiting/3InputVersion.rar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐