Skip to content

Commit 7161299

Browse files
committed
Take another approach
1 parent 9c5a7b0 commit 7161299

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/Sql/Sql/Services/Util.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System;
1717
using System.Globalization;
1818
using System.Linq;
19-
using System.Net.Mail;
2019
using System.Text.RegularExpressions;
2120

2221
namespace Microsoft.Azure.Commands.Sql.Services
@@ -103,20 +102,12 @@ public static bool AreEmailAddressesInCorrectFormat(string[] emailAddresses)
103102
{
104103
return true;
105104
}
106-
return !emailAddresses.Any(e => !IsValidEmailAddress(e));
107-
}
108105

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()));
120111
}
121112
}
122113
}

0 commit comments

Comments
 (0)