How can I make a textbox only accept a valid email?

This question already has an answer here: C# code to validate email address 34 answers .NET可以为你做到这一点: try { var eMailValidator = new System.Net.Mail.MailAddress("xyz@blabla.com"); } catch (FormatException ex) { // wrong e-mail address } 检查Mailadress课程 var test = new MailAddress("emailadres"); If you'

如何让文本框只接受有效的电子邮件?

这个问题在这里已经有了答案: 验证电子邮件地址的C#代码34个答案 .NET可以为你做到这一点: try { var eMailValidator = new System.Net.Mail.MailAddress("xyz@blabla.com"); } catch (FormatException ex) { // wrong e-mail address } 检查Mailadress课程 var test = new MailAddress("emailadres"); 如果你正在开发一个web应用程序,现

c# should i use string with regex matchs or not

I have a text that I am going to find matchs within that text and after that putting the results on array . when I tried to make string array and string variables I found that it's really confusing to change from MatchCollection type to String type . and I get the error cannot convert . what type of array and variables should I use ? and what is the need for string type . I was just us

我应该使用字符串与正则表达式匹配或不

我有一段文字,我将在该文本中查找匹配,然后将结果放在数组中。 当我试图创建字符串数组和字符串变量时,我发现将MatchCollection类型更改为字符串类型确实令人困惑。 我得到的错误不能转换。 我应该使用什么类型的数组和变量? 什么是字符串类型的需要。 我正在使用它,因为我处理字符串。 我想注意到,我将在数组之间进行比较以找出常见匹配 这里是我的完整代码到目前为止c#正则表达式数组或列表和哪个类型的字符

C# Create array from MatchCollection

i need to create an multidimensional array from this regex result MatchCollection match = Regex.Matches(input, @"( +|)[( +|)PC( +|)(( +|)name( +|)=" + ""(.*)"( +|),( +|)ip( +|)=( +|)"(.*)"( +|),( +|)subnet( +|)=( +|)"(.*)"( +|),( +|)gateway( +|)=( +|)"(.*)"" + @")]"); that regex will catch this string [PC(name="PC1", ip="192.168.1.2", subnet="255.255.255.0", gateway="192.168.1.1")] and what i

C#从MatchCollection创建数组

我需要从这个正则表达式结果创建一个多维数组 MatchCollection match = Regex.Matches(input, @"( +|)[( +|)PC( +|)(( +|)name( +|)=" + ""(.*)"( +|),( +|)ip( +|)=( +|)"(.*)"( +|),( +|)subnet( +|)=( +|)"(.*)"( +|),( +|)gateway( +|)=( +|)"(.*)"" + @")]"); 该正则表达式会捕获这个字符串 [PC(name="PC1", ip="192.168.1.2", subnet="255.255.255.0", gateway="192.168.1.1")] 我需要的是创建像这样的多维数组 [0]PC

regex to remove vowels from string except first and last charаcter

I am trying to remove all the vowels from a string except for the first and last character. I have tried with 2 expressions and using 2 ways but in vain. I have described them below. Does anybody has a regular expression for this? eg original string -- source = apeaple after regex -- source_modified = apple (this is what is expected) I tried the expression ([a-zA-Z])[aeiouAEIOU]([a-zA-

正则表达式除去第一个和最后一个字符串之外的字符串中的元音

我试图从字符串中除去第一个和最后一个字符的所有元音。 我用2个表达式尝试了两种方法,但徒劳无益。 我在下面描述了它们。 有人有这样的正则表达式吗? 例如 原始字符串 - 来源= apeaple 正则表达式后 - source_modified =苹果(这是预期的) 我尝试了表达式([a-zA-Z])[aeiouAEIOU]([a-zA-Z])但是这个表达式也删除了重复的字符。 所以,当我应用上述表达式时发生以下情况 使用的代码 - Regex reg = new Regex(

Using Regex to edit a string in C#

I'm just beginning to use Regex so bear with my terminology. I have a regex pattern that is working properly on a string. The string could be in the format "text [pattern] text". Therefore, I also have a regex pattern that negates the first pattern. If I print out the results from each of the matches everything is shown correctly. The problem I'm having is I want to add te

使用正则表达式在C#中编辑字符串

我刚刚开始使用正则表达式,所以忍受我的术语。 我有一个在字符串上正常工作的正则表达式模式。 该字符串可以是格式“text [pattern] text”。 因此,我也有一个否定第一种模式的正则表达式模式。 如果我打印出每场比赛的结果,所有内容都能正确显示。 我遇到的问题是我想将文本添加到字符串中,它会更改正则表达式MatchCollection中匹配的索引。 例如,如果我想在“td”匹配“/ td”“标签中包含找到的匹配项,我有以下代码: R

Can I use dynamic in a .NET Standard class library?

I'm having a hard time trying to migrate from regular Windows desktop development to ASP.NET Core MVC. One issue I'm coming across is to create my solution. I would like to remove everything that is not UI related from the default project that ships with VS 2015 and put into a separated project. I noticed that ASP MVC Core references to .NETCoreApp and the Class Library project refere

我可以在.NET标准类库中使用动态吗?

我很难尝试从常规Windows桌面开发迁移到ASP.NET Core MVC。 我遇到的一个问题是创建我的解决方案。 我想从VS 2015随附的默认项目中移除与UI无关的所有内容,并将其放入单独的项目中。 我注意到ASP MVC Core引用了.NETCoreApp ,而类库引用了.NETStandard 。 我的问题是我需要在类库中使用动态keyworkd,但它不支持它。 MVC项目支持没有任何问题。 我想这是因为不同的.NET版本。 NETStandard和NETCoreApp有什么区别?

Can anyone tell me why this C# email validation regular expression (regex) hangs?

I got a good email vaidation regex from: Email regular expression public static void Main(string[] args) { string value = @"cvcvcvcvvcvvcvcvcvcvcvvcvcvcvcvcvvccvcvcvc"; var regex = new Regex( @"^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[a-zA-Z]{2,9})$", RegexOptions.Compiled); var x = regex.Match(value); // Hangs here

任何人都可以告诉我为什么这个C#电子邮件验证正则表达式(正则表达式)挂起?

我从电子邮件正则表达式中获得了一个很好的email vaidation正则表达式 public static void Main(string[] args) { string value = @"cvcvcvcvvcvvcvcvcvcvcvvcvcvcvcvcvvccvcvcvc"; var regex = new Regex( @"^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[a-zA-Z]{2,9})$", RegexOptions.Compiled); var x = regex.Match(value); // Hangs here

C# email regex with no space or ! character allowed

so i have this piece of code and what i need help with is: i need it to not allow spaces (eg user 123@hotmail.com = invalid) i need it to allow all characters except the ! character. i need the domain (after . ) that if more than 2 characters long, must be validated by a supplied file which i have here. the country codes are. AERO, BIZ, COM, COOP, EDU, GOV, INFO, INT, MIL, MUSEUM, NAME,

C#电子邮件正则表达式没有空间或! 字符允许

所以我有这段代码,我需要帮助的是: 我需要它不允许空格(例如user 123@hotmail.com =无效) 我需要它来允许除了! 字符。 我需要的域(后. ),如果超过2个字符长,必须通过我提供的文件进行验证。 国家代码是。 AERO,BIZ,COM,COOP,EDU,GOV,INFO,INT,MIL,MUSEUM,NAME,NET,ORG,PRO 当前代码。 private void validateBtn_Click(object sender, EventArgs e) { Regex email = new Regex(@"[a-zA-Z0-9

Regular expression for email and 'No Email'

Need regular expression to validate email address also if user don't have email, user able to type 'No Email'. such that regular expression should validate 'No Email' as a valid string. @"^(([w.-]+)@([w-]+)((.(w){2,3})+)|(No Email))$" You can combine your regex with an or expression | var regex = "(.+@.+..+|No Email)" http://refiddle.com/h2x The validation part need so

电子邮件和“无电子邮件”的正则表达式

需要正则表达式来验证电子邮件地址,如果用户没有电子邮件,用户可以键入“无电子邮件”。 这样正则表达式应该将“无电子邮件”验证为有效的字符串。 @"^(([w.-]+)@([w-]+)((.(w){2,3})+)|(No Email))$" 你可以将你的正则表达式与一个或表达式|相结合 var regex = "(.+@.+..+|No Email)" http://refiddle.com/h2x 验证部分需要一些改进(不符合RFC),但你明白了。

Regular expression to validate comma separated email addresses?

I need to validate email addresses which can be single or several comma-separated ones. Before I was using in a regular expression validator an expression like: string exp = @"((w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*)*([,])*)*"; and it was validating multiple or one single email address. But same expression is not valdiating in C#? It says valid to invalid addresses as well. Please correc

正则表达式来验证逗号分隔的电子邮件地址?

我需要验证可以是单个或多个逗号分隔的电子邮件地址。 在我使用正则表达式验证器之前,我需要一个表达式: string exp = @"((w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*)*([,])*)*"; 它正在验证多个或一个电子邮件地址。 但是同样的表达式在C#中是不会起作用的? 它对有效地址也是有效的。 请纠正我或建议我使用表达式来验证电子邮件地址。 请提供更多细节。 哪些地址被认定为有效,但应该是无效的? 你如何调用正则