Common/MyValidate.cs

(完整代码) 2KB

using Microsoft.VisualBasic;
using System;
using System.Text.RegularExpressions;
namespace Common
{
    public class MyValidate
    {
        public static bool IsDate(string InPut)
        {
            Regex regex = new Regex(@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
            return regex.IsMatch(InPut);
        }

        public static bool IsEmail(string InPut)
        {
            Regex regex = new Regex(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", RegexOptions.IgnoreCase);
            return regex.IsMatch(InPut);
        }
        public static bool IsUName(string InPut)
        {
            Regex regex = new Regex(@"^\w+$", RegexOptions.IgnoreCase);
            return regex.IsMatch(InPut);
        }
        public static bool IsIP(string InPut)
        {
            return Regex.IsMatch(InPut, @"^(\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]\d|25[0-5])$");
        }

        public static bool IsNumeric(string InPut)
        {
            return IsNumeric(InPut, false, false);
        }

        public static bool IsNumeric(string InPut, bool AllowNegative, bool AllowDecimal)
        {
            return Information.IsNumeric(InPut);
        }

        public static bool IsSQL(string InPut)
        {
            Regex regex = new Regex(@"\?|Truncate%20|Truncate\s+|ALTER%20|ALTER\s+|select%20|select\s+|insert%20|insert\s+|delete%20|delete\s+|count\(|drop%20|drop\s+|update%20|update\s+", RegexOptions.IgnoreCase);
            return regex.IsMatch(InPut);
        }

        public static bool IsURL(string InPut)
        {
            return Regex.IsMatch(InPut, "^(http|ftp|file)://.*");
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。