/// <summary>
/// 判斷是否為正確的IP地址,IP範圍(0.0.0.0~255.255.255)
/// </summary>
/// <param name="ip">需驗證的IP地址</param>
/// <returns></returns>
public bool IsIP(String ip)
{
return System.Text.RegularExpressions.Regex.Match(ip, @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$").Success;
}
/// <summary>
/// 判斷是否為正確的MAC地址,地址中間不能有分隔字元,如:“-”、“:”等。
/// </summary>
/// <param name="mac">需驗證的MAC地址</param>
/// <returns></returns>
public bool IsMAC(String mac)
{
return System.Text.RegularExpressions.Regex.Match(mac, "^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$").Success;
}
public bool IsMail(string mail)
{
return System.Text.RegularExpressions.Regex.Match(mail, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").Success;
}
/// <summary>
/// 是否為Double類型
/// </summary>
/// <param name="expression"></param>
/// <returns></returns>
public static bool IsDouble(object expression)
{
if (expression != null)
{
return Regex.IsMatch(expression.ToString(), @"^([0-9])[0-9]*(\.\w*)?$");
}
return false;
}