如何使文本框仅接受C#中的电子邮件地址 [英] How to make textbox accept only email address in C#

查看:88
本文介绍了如何使文本框仅接受C#中的电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想知道如何验证仅接受电子邮件地址的文本框

谢谢:d

hey i want to know how to validate textbox that it only accepts email address

thanks :d

推荐答案

您可能想研究常规表达式 [ ^ ](此处为更多C#特定文章 [
You''ll probably want to look into Regular Expressions[^] (and here''s a more C# specific article[^] on how to use them). Fortunately for you, there should be plenty of existing patterns for checking email addresses, as it''s a very common use for them.


Expresso是一款很好的免费工具,用于测试正则表达式,它可以从
下载
http://www.ultrapico.com/Expresso.htm [
Expresso is good free tool to test regular expressions and it can be downloaded from

http://www.ultrapico.com/Expresso.htm[^]

If you are using Windows forms, then in Validating event of the TextBox, test the TextBox.Text property using Regex.IsMatch method for the pattern of email. If it fails then set e.Cancel = true else set e.Cancel = false

If your problem is solved you may accept and vote the solution, otherwise please post your queries

PES

[edit]Spelling mistake in It it fails corrected to If it fails[/edit]


这篇关于如何使文本框仅接受C#中的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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