记录点滴

记录生活

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
来源:http://www.strivingprogrammers.com/articles/10-regular-expression-validator-for-checking-different-kinds-of-e-mail-address.aspx

原文:

I was working on Regular Expression Validator and found a very strong expression for checking validity of all kinds of e-mail addresses. So here i am sharing it with you guys:

Here's the expression:

         

^([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})|([\w\d\-]+\.[\w\d\-]{1,67}))\.(([a-zA-Z\d]{2,4})(\.[a-zA-Z\d]{2})?)$




Here's the way it can be used in ASP.NET Regular Expression Validator:


<asp:RegularExpressionValidator runat="server" ID="EmailAddress" Display="Dynamic" ControlToValidate="txtFirstName" ErrorMessage="Please enter a valid e-mail address" ValidationExpression="^([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})|([\w\d\-]+\.[\w\d\-]{1,67}))\.(([a-zA-Z\d]{2,4})(\.[a-zA-Z\d]{2})?)$" ValidationGroup="CreateUserForm">*</asp:RegularExpressionValidator>



Matches: name@domain.com | name@sub-domain.com.au | name@sub1.sub2.domain | name@organization.co.uk | name@domain.tv | name@domain.four | name@mailbox.com.us

Non-Matches: www.domain.com | name@.com | name@domain..com | name@anything@.com | name@com

posted on 2011-11-16 09:30  啊峰  阅读(167)  评论(0编辑  收藏  举报