开发者

ASP.NET Allow + Symbol in email validation expression

Hey I have the follow email validation express开发者_C百科ion

^[\w-.]+@([\w-]+.)+[\w-]{2,4}$

What I am looking for is for email addresses to be allowed which have a "+" before the @ part of the email cheers


Or use a full RFC 822 regex

^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$

And the RegexLib is great place for finding regex for most requirements, you are rarely the first to want to do something.


Just change it to ^[\w-.]+(?:\+[\w]*)?@([\w-]+.)+[\w-]{2,4}$

This allows for + before @ and some characters which is optional. So aliostad@gmail.com aliostad+ali@gmail.com are both valid.

Updated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜