本文实例讲述了C#常用正则验证函数。分享给大家供大家参考,具体如下:
1、Ip地址验证
/// <summary>
/// Ip地址验证
/// </summary>
public static bool CheckIp(string ip)
{
bool result = false;
Regex ipReg = new Regex(@^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]