示例#1
0
        /// <summary>
        /// 判断日期是否正确
        /// </summary>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="day">日</param>
        /// <returns>True: 正确日期 False: 非法日期</returns>
        public static bool IsDateValid(string year, string month, string day)
        {
            int y, m, d;

            if (!VerifyTool.IsInt(year, false, false, out y))
            {
                return(false);
            }
            if (!VerifyTool.IsInt(month, false, false, out m))
            {
                return(false);
            }
            if (!VerifyTool.IsInt(day, false, false, out d))
            {
                return(false);
            }

            return(IsDateValid(y, m, d));
        }
示例#2
0
        /// <summary>
        /// 判断IP地址是否正确
        /// </summary>
        /// <param name="ip">IP地址</param>
        /// <returns>True: 正确 False: 错误</returns>
        public static bool IsIPValid(string ip)
        {
            if (!string.IsNullOrEmpty(ip))
            {
                string pat = @"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$";

                Match m = Regex.Match(ip, pat);
                if (m != null && m.Groups.Count == 5)
                {
                    for (int i = 1; i < 5; i++)
                    {
                        if (!VerifyTool.IsByte(m.Groups[i].Value))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                return(false);
            }
            return(false);
        }