11-10-17

来源:互联网 发布:微信三级分销商城源码 编辑:程序博客网 时间:2024/06/05 13:29

验证ip地址:

using System.Text.RegularExpressions;


 public static bool IsIPAddress(string str1)
    {
        if (str1 == null || str1 == string.Empty || str1.Length < 7 || str1.Length > 15) return false;


        string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";


        Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);


        return regex.IsMatch(str1);
    }

利用正则表达式来验证,可以直接放在类中,然后就可以直接调用了。

原创粉丝点击