C#中的验证控件 [英] Validation Controls in C#

查看:158
本文介绍了C#中的验证控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在C#windows应用程序中工作。我创建了2个texbox,即电子邮件ID和电话号码。我们应该使用哪些验证电子邮件ID和密码。提前谢谢阅读我的留言。



问候

Balamurugan

解决方案

你好,



您需要在Windows应用程序中使用错误提供程序控件进行此类验证。



请参阅下面的链接有很好的解释。



http://www.c-sharpcorner.com/UploadFile/scottlysle/UseErrorProvider03082007210138PM/UseErrorProvider.aspx [ ^ ]



现在,对于电子邮件验证部分,你可以如下标准正则表达式。或者你可以编写自己的正则表达式来满足你的需要。

  @  ^([\w\.\  - ] +)@([\w\  - ] +)(。(\(\w){2,3})+)






希望有所帮助,如果有,请将答案标记为解决方案/ upvote。



谢谢

Milind


试用此代码:



电子邮件ID:



  private   void  textMailid_Validating( object  sender,CancelEventArgs e)
{
System .Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex( @ ^ [A-ZA-Z] [\w\ .-] {2,28} [A-ZA-Z0-9] @ [A-ZA-Z0-9] [\\ \\w\ .-] * [A-ZA-Z0-9] \。[A-ZA-Z] [A-ZA-Z \。] * [A-ZA-Z]

Hi,
I'm working in C# windows application.I have created 2 texboxes namely email ID and Phone number.What are the validations we should used for Email id and password.Thanks in advance for reading my message.

Regards
Balamurugan

解决方案

Hi There,

You need to use error provider controls for such validation in windows application.

Please see a link below which has got good explanation.

http://www.c-sharpcorner.com/UploadFile/scottlysle/UseErrorProvider03082007210138PM/UseErrorProvider.aspx[^]

Now, for email validation part, you can use a standard regex available as below. Or you can write your own regex to suit your need.

@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)


"



Hope that helps, If it does, mark the answer as solution/upvote.

Thanks
Milind


Try this Code:

Email Id:

private void textMailid_Validating(object sender, CancelEventArgs e)
        {
            System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]


这篇关于C#中的验证控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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