标签:
接上一篇,有三个输入框,都要求输入1-6个英文字符或数字。
测试用例:
09aaaaa | 不合法 |
0+09 | 不合法 |
009a | 合法输入 |
下面是测试结果:
源代码如下:
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; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; label4.Text = "请先输入"; } private void button1_Click_1(object sender, EventArgs e) { String[] str = new String[3]; str[0] = textBox1.Text; str[1] = textBox2.Text; str[2] = textBox3.Text; Boolean res1 = System.Text.RegularExpressions.Regex.IsMatch(str[0], @"^[a-zA-Z\d]{1,6}$"); Boolean res2 = System.Text.RegularExpressions.Regex.IsMatch(str[1], @"^[a-zA-Z\d]{1,6}$"); Boolean res3 = System.Text.RegularExpressions.Regex.IsMatch(str[2], @"^[a-zA-Z\d]{1,6}$"); if (res1) label4.Text = "用户名输入正确"; else label4.Text = "用户名输入不正确"; if (res2) label5.Text = "密码输入正确"; else label5.Text = "密码输入不正确"; if (res3) label6.Text = "验证码输入正确"; else label6.Text = "验证码输入不正确"; } } }
标签:
原文地址:http://www.cnblogs.com/dengye/p/4376063.html