使用错误提供程序的Windows窗体验证 [英] Windows Form validation using error provider

查看:53
本文介绍了使用错误提供程序的Windows窗体验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要使用Errorprovider验证Windows窗体.
我的表单中有四个文本框
名称,电话号码,薪水,电子邮件编号
1)所有四个文本框都不接受空数据.
2)名称文字框只能接受字母,并且名称长度不得少于3个字符.
3)phonenumber只能接受整数值,不能接受负值,并且长度应为10位数.
4)薪水只接受整数,不接受负值.
5)电子邮件ID是一种特定格式.

有人可以向我解释.

谢谢&问候,
乔兹纳

解决方案

欢迎访问MSDN论坛.

请参阅您的描述,您可以查看一下 如何:使用Windows Forms ErrorProvider组件显示错误图标以进行表单验证

这里有C#/C ++/VB的示例代码,您可以使用textBox1_Validating方法检查文本框的文本是否符合您的要求.

对于每个文本框的详细判断条件,您需要使用正则表达式来实现您的要求如下所示:

名称:^ [a-zA-Z] {1,3}


电子邮件: \ w [-\ w.+] * @([[A-Za-z0-9] [-A-Za-z0-9] + \.)+ [A-Za-z] {2,14}

对于代码: if(!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text," ^ [a-zA-Z] {1,3}


")) 然后显示错误消息.

对于其他文本框的规则,您可以按以下方式搜索有关正则表达式的信息您的详细要求和开发语言,应该有一些有用的 有助于您解决问题的信息.

最好的问候,

Sara


Hi All,

I need to validate my windows form using Errorprovider.
i have four textbox in my form
name, phonenumber, salary,emailId
1)All four textbox is not accept empty data.
2)name textbox accept only alphabets and name length should not less then 3 character.
3)phonenumber should accept only integer value and, not accept negative value and length should be 10 digit.
4)salary only accept integer, not accept negative value.
5)email id is a specific format.

can someone explain me.

Thanks & Regards,
Jyotsna

解决方案

Hi Jyotsna,

Welcome to the MSDN forum.

Refer to your description, you can have a look at this How to: Display Error Icons for Form Validation with the Windows Forms ErrorProvider Component

There has the example code for C#/C++/VB and you can the method textBox1_Validating to check if the text of textbox is match your requirement or not.

For the detail judgment condition of each textbox, you need to use the regular expression to achieve your requirement like the following:

Name: ^[a-zA-Z]{1,3}


Email: \w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}

For code: if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]{1,3}


")) then display the error message.

For the rule of the other textboxes, you can search the information about the regular expression per your detail requirement and develop language, there should have some useful information that helpful for your question.

Best regards,

Sara


这篇关于使用错误提供程序的Windows窗体验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆