public static string IsValidMAC(string macAddress)
{
if (macAddress.StartsWith("/spa")) macAddress = macAddress.Substring(4);
macAddress = macAddress.Replace(":", "");
string result = "";
Regex rx = new Regex("([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase);
Match m = rx.Match(macAddress);
result = m.Groups[0].Value;
if (result.Length == 17)
{
return result;
}
else
{
rx = new Regex("([0-9a-fA-F][0-9a-fA-F]){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase);
Match m2 = rx.Match(macAddress);
result = m2.Groups[0].Value;
if (result.Length == 12)
{
return result;
}
return result;
}
}
0 comments:
Post a Comment