Tag: rfc

System.Net.MailMessage允许一些无效的电子邮件地址格式

许多人可能已经意识到,正确validation电子邮件地址可能有点噩梦。 您可以整天搜索与当前RFC标准匹配的C#正则表达式,并且您将找到可以提供不同结果的不同正则表达式。 如果查看http://en.wikipedia.org/wiki/Email_address#Local_part ,您将看到不允许在本地部分的开头或结尾处出现句点。 也不允许连续两个时期。 但是,以下NUnit测试certificateSystem.Net.MailMessage允许您为某些无效的电子邮件地址格式实例化MailMessage对象。 [Test] [TestCase(@”foobar@exampleserver”)] //technically valid from the wiki article [TestCase(@”jsmith@[192.168.2.1]”)] //technically valid from the wiki article [TestCase(@”niceandsimple@example.com”)] //vanilla email address [TestCase(@”very.common@example.com”)] //also standard [TestCase(@”a.little.lengthy.but.fine@dept.example.com”)] //long with lots of periods [TestCase(@”disposable.style.email.with+symbol@example.com”)] //disposable with the + symbol [TestCase(@”other.email-with-dash@example.com”)] //period and dash in local part [TestCase(@”user-test-hyphens@example-domain.com”)] //lots of hyphens [TestCase(@”!#$%&’*+-/=?^_`{|}~@example-domain.com”)] //all these symbols […]

用于validation多个电子邮件地址的正则表达式

我有一个正则表达式validation我的邮件地址是这样的: ([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?) 这完全正常,但只允许输入一封电子邮件。 现在我想扩展它并允许添加多个邮件地址(例如,就像MS Outlook一样),并使用分号作为邮件分割器。 mail1@tld.com;mail2@tld.com;mail3@tld.com 现在我搜索并找到了这个: ([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}(;|$)) 这在一点上有效,但遗憾的是在邮件末尾需要一个分号: mail1@tld.com; 当用户只输入一封电子邮件时,这不是我想要的。 如何扩展我的正则表达式(第一个)以允许添加多个邮件地址,同时让它们通过分号分割?