思想来源于Jquery表单验证,可以像使用jQuery验证方法来验证winform
Code
1this.textBox1.InputValidate(new InputValidateMetaData()
2 {
3 ValidateGroupName = "Form1",
4 Type = WinFormValidator.ValidateType.String,
5 Min = "5",
6 Max = "10",
7 ShowMsg = "请输入5-10个字符",
8 SuccessMsg = "输入正确",
9 FailedMsg = "输入错误",
10 });
11
12 this.textBox2.RegexValidate(new RegexValidateMetaData()
13 {
14 ValidateGroupName = "Form1",
15 Type = WinFormValidator.ValidateType.Regex,
16 Pattern = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$",
17 ShowMsg = "请输入ip地址",
18 SuccessMsg = "输入正确",
19 FailedMsg = "输入错误",
20 });
21
22 this.textBox3.FunctionValidate(new FunctionValidateMetaData() {
23 Type = ValidateType.Function,
24 ValidateGroupName = "Form1",
25 ShowMsg = "请输入5-10个字符",
26 SuccessMsg = "输入正确",
27 FailedMsg = "输入错误",
28 FunctionEvent = new FunctionEventHandler(functionValidate),
29 });
1this.textBox1.InputValidate(new InputValidateMetaData()
2 {
3 ValidateGroupName = "Form1",
4 Type = WinFormValidator.ValidateType.String,
5 Min = "5",
6 Max = "10",
7 ShowMsg = "请输入5-10个字符",
8 SuccessMsg = "输入正确",
9 FailedMsg = "输入错误",
10 });
11
12 this.textBox2.RegexValidate(new RegexValidateMetaData()
13 {
14 ValidateGroupName = "Form1",
15 Type = WinFormValidator.ValidateType.Regex,
16 Pattern = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$",
17 ShowMsg = "请输入ip地址",
18 SuccessMsg = "输入正确",
19 FailedMsg = "输入错误",
20 });
21
22 this.textBox3.FunctionValidate(new FunctionValidateMetaData() {
23 Type = ValidateType.Function,
24 ValidateGroupName = "Form1",
25 ShowMsg = "请输入5-10个字符",
26 SuccessMsg = "输入正确",
27 FailedMsg = "输入错误",
28 FunctionEvent = new FunctionEventHandler(functionValidate),
29 });