File tree Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Original file line number Diff line number Diff line change 16
16
using System ;
17
17
using System . Globalization ;
18
18
using System . Linq ;
19
- using System . Net . Mail ;
20
19
using System . Text . RegularExpressions ;
21
20
22
21
namespace Microsoft . Azure . Commands . Sql . Services
@@ -103,20 +102,12 @@ public static bool AreEmailAddressesInCorrectFormat(string[] emailAddresses)
103
102
{
104
103
return true ;
105
104
}
106
- return ! emailAddresses . Any ( e => ! IsValidEmailAddress ( e ) ) ;
107
- }
108
105
109
- private static bool IsValidEmailAddress ( string mailAddress )
110
- {
111
- try
112
- {
113
- new MailAddress ( mailAddress ) ;
114
- return true ;
115
- }
116
- catch
117
- {
118
- return false ;
119
- }
106
+ var emailRegex =
107
+ new Regex ( string . Format ( "{0}{1}" ,
108
+ @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" ,
109
+ @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$" ) ) ;
110
+ return ! emailAddresses . Any ( e => ! emailRegex . IsMatch ( e . ToLower ( ) ) ) ;
120
111
}
121
112
}
122
113
}
You can’t perform that action at this time.
0 commit comments