Exemplo n.º 1
0
 public ActiveItem(string text, RegexType type, int startIndex, int lastIndex)
 {
     this.Text       = text;
     this.Type       = type;
     this.StartIndex = startIndex;
     this.LastIndex  = lastIndex;
 }
Exemplo n.º 2
0
        public bool isValid(string input, RegexType type)
        {
            string regexString = "";

            switch (type)
            {
            case RegexType.Email:
                regexString =
                    @"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*" +
                    "@" +
                    @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$";
                break;

            case RegexType.Nr_4Digits:
                regexString = @"\d{4}";
                break;

            default:
                break;
            }
            Regex regex = new Regex(regexString);
            Match match = regex.Match(input);

            return(match.Success);
        }
        public async Task<ActionResult<RegexType>> PostRegexType(RegexType regexType)
        {
            _context.RegexTypes.Add(regexType);
            await _context.SaveChangesAsync();

            return CreatedAtAction("GetRegexType", new { id = regexType.Id }, regexType);
        }
Exemplo n.º 4
0
 static public void esValido(String nombreCampo, String aValidar, RegexType regex)
 {
     if (!Regex.IsMatch(aValidar, regex.Regex()))
     {
         camposInvalidos += "Campo inválido: " + nombreCampo + ", ya que no cumple con la restricción de:\n " + regex.Significado() + "\n";
     }
 }
Exemplo n.º 5
0
        public static DateTime?MakeDatetime(string dateTimeString, RegexType regexType = RegexType.All)
        {
            List <RegexMatcher> matchers = null;

            switch (regexType)
            {
            case RegexType.Exif:
                matchers = new List <RegexMatcher>()
                {
                    new RegexMatcher(_exifFormat1, _exifFormat1_Match),
                    new RegexMatcher(_exifFormat2, _exifFormat2_Match),
                };
                break;

            default:
                matchers = _matchers;
                break;
            }

            foreach (var regexMatcher in matchers)
            {
                var m = regexMatcher.Item1.Match(dateTimeString);
                if (m.Success)
                {
                    return(regexMatcher.Item2(m));
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        public static bool ValidateAgainstRegex(RegexType expressionType, string text)
        {
            var ExpressionString = string.Empty;

            switch (expressionType)
            {
            case RegexType.Email:
                ExpressionString = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
                break;

            case RegexType.ZipCode:
                ExpressionString = "\\d{5}(-\\d{4})?";
                break;

            case RegexType.Year:
                ExpressionString = "\\d{4}";
                break;

            case RegexType.ComplexPassword:
                ExpressionString = "\\w{6,}";
                break;

            case RegexType.SpecialCharacters:
                ExpressionString = @"[^\w\.@-]";
                break;
            }

            return(ValidateAgainstRegex(ExpressionString, text));
        }
Exemplo n.º 7
0
		public static bool ValidateAgainstRegex(RegexType expressionType, string text)
		{
			var ExpressionString = string.Empty;

			switch (expressionType)
			{
				case RegexType.Email:
					ExpressionString = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
					break;
				case RegexType.ZipCode:
					ExpressionString = "\\d{5}(-\\d{4})?";
					break;
				case RegexType.Year:
					ExpressionString = "\\d{4}";
					break;
				case RegexType.ComplexPassword:
					ExpressionString = "\\w{6,}";
					break;
				case RegexType.SpecialCharacters:
					ExpressionString = @"[^\w\.@-]";
					break;
			}

			return ValidateAgainstRegex(ExpressionString, text);
		}
Exemplo n.º 8
0
        /// <summary>
        /// 使用正则表达式检查字符串
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        /// <returns>返回识别到的字符数</returns>
        public static string RegexChecked(string str, RegexType type)
        {
            string pattern = null;

            switch (type)
            {
            case RegexType.Normal:
                pattern = @"[\u0022\u0391-\uFFE5\r\n a-zA-Z0-9`=\'\-\\\[\] ;,./~!@#$%^&*()_+|{}:<>?]{0,}";
                break;

            case RegexType.Password:
                pattern = @"[\u0022a-zA-Z0-9`=\-\\\[\] ;,./~!@#$%^&*()_+|{}:<>?]{0,}";
                break;

            case RegexType.Ip:
                pattern =
                    @"((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))";
                break;

            case RegexType.PosInt:
                pattern = @"[0-9]*[1-9][0-9]*";
                break;

            case RegexType.Number:
                var sign = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                pattern = string.Format("[1-9]+[0-9]*([{0}][0-9]+)?|[0-9]([{0}][0-9]+)?", sign);
                break;
            }
            return(RegexChecked(str, pattern));
        }
        public async Task<IActionResult> PutRegexType(int id, RegexType regexType)
        {
            if (id != regexType.Id)
            {
                return BadRequest();
            }

            _context.Entry(regexType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RegexTypeExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Exemplo n.º 10
0
        public static string OnTextChange(string text, RegexType regexType, MaxLength maxLength)
        {
            if (text.Trim().Length > (int)maxLength)
            {
                text = text.Substring(0, (int)maxLength);
                return(text);
            }
            var NombreRegex = regexType.GetStringValue();

            text = text.TrimStart().ToUpper().Replace("  ", " ");

            bool EsValido = (Regex.IsMatch(text, NombreRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));

            if (!EsValido)
            {
                if (text.Length > 1)
                {
                    text = text.Remove(text.Length - 1);
                }
                else
                {
                    text = "";
                }
            }
            return(text);
        }
        private static Regex GetRegexByRegexType(RegexType regexType)
        {
            Dictionary <RegexType, Regex> regexTypeToRegex = new Dictionary <RegexType, Regex>();

            regexTypeToRegex.Add(RegexType.Variable, variableRegex);
            regexTypeToRegex.Add(RegexType.Parentheses, parenthesesRegex);
            regexTypeToRegex.Add(RegexType.UnaryOperation, unaryOperationRegex);
            regexTypeToRegex.Add(RegexType.UnaryOperand, unaryOperandRegex);
            return(regexTypeToRegex[regexType]);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Supprime les matches de la chaine de caractères passée en paramètre.
 /// </summary>
 /// <param name="regexType">type de regex</param>
 /// <param name="input">chaine à nettoyer</param>
 /// <param name="trim">Si vrai, nettoie le résultat des espaces générés</param>
 /// <returns></returns>
 public static string Remove(this string input, RegexType regexType, bool trim)
 {
     if (trim)
     {
         return(new Regex(EnumHelper.ToDescription(regexType)).Replace(input, string.Empty).Trim());
     }
     else
     {
         return(new Regex(EnumHelper.ToDescription(regexType)).Replace(input, string.Empty));
     }
 }
        public static void AddWireRegex(RegexType regexType, string st, string sp, string et, string ep)
        {
            if (string.IsNullOrEmpty(st) ||
                string.IsNullOrEmpty(sp) ||
                string.IsNullOrEmpty(et) ||
                string.IsNullOrEmpty(ep))
            {
                return;
            }

            ref List <WireRegex> wireRegexList = ref GetWireListForRegexType(regexType);
Exemplo n.º 14
0
        public static RegexItem GetRegexItem(RegexType type)
        {
            RegexItem item = new RegexItem();

            switch (type)
            {
            case RegexType.Int: { item.RegexString = RegexHelper.Int; item.RegexMessage = RegexHelper.IntMsg; }
            break;

            case RegexType.Float: { item.RegexString = RegexHelper.Float; item.RegexMessage = RegexHelper.FloatMsg; }
            break;

            case RegexType.Email: { item.RegexString = RegexHelper.Email; item.RegexMessage = RegexHelper.EmailMsg; }
            break;

            case RegexType.Tel: { item.RegexString = RegexHelper.Tel; item.RegexMessage = RegexHelper.TelMsg; }
            break;

            case RegexType.Mobile: { item.RegexString = RegexHelper.Mobile; item.RegexMessage = RegexHelper.MobileMsg; }
            break;

            case RegexType.En: { item.RegexString = RegexHelper.En; item.RegexMessage = RegexHelper.EnMsg; }
            break;

            case RegexType.Cn: { item.RegexString = RegexHelper.Cn; item.RegexMessage = RegexHelper.CnMsg; }
            break;

            case RegexType.Url: { item.RegexString = RegexHelper.Url; item.RegexMessage = RegexHelper.UrlMsg; }
            break;

            case RegexType.IP: { item.RegexString = RegexHelper.IP; item.RegexMessage = RegexHelper.IPMsg; }
            break;

            case RegexType.Zip: { item.RegexString = RegexHelper.Zip; item.RegexMessage = RegexHelper.ZipMsg; }
            break;

            case RegexType.Alpha: { item.RegexString = RegexHelper.Alpha; item.RegexMessage = RegexHelper.AlphaMsg; }
            break;

            case RegexType.IdCard: { item.RegexString = RegexHelper.IdCard; item.RegexMessage = RegexHelper.IdCardMsg; }
            break;

            case RegexType.CarNo: { item.RegexString = RegexHelper.CarNo; item.RegexMessage = RegexHelper.CarNoMsg; }
            break;

            case RegexType.QQ: { item.RegexString = RegexHelper.QQ; item.RegexMessage = RegexHelper.QQMsg; }
            break;

            case RegexType.Msn: { item.RegexString = RegexHelper.Msn; item.RegexMessage = RegexHelper.MsnMsg; }
            break;
            }
            return(item);
        }
        private static ref List <WireRegex> GetWireListForRegexType(RegexType regexType)
        {
            if (regexType == RegexType.Include)
            {
                return(ref Wire_Includes);
            }
            if (regexType == RegexType.Ignore)
            {
                return(ref Wire_Ignores);
            }

            throw new Exception();
        }
Exemplo n.º 16
0
        string GetTypeName(MethodFormRouteData methodFormRouteData)
        {
            var match = RegexType.Match(methodFormRouteData.Form);

            if (match.Success == false)
            {
                return(string.Empty);
            }
            var value = match.Groups["Type"].Value;

            if (string.IsNullOrEmpty(this.TypeTemplate))
            {
                return(value);
            }
            return(string.Format(this.TypeTemplate, value));
        }
Exemplo n.º 17
0
        public static Regex GetRegex(RegexType rt)
        {
            switch (rt)
            {
            case RegexType.RemoveLastDot:
                return(_re_RemoveLastDot.Value);

            case RegexType.ProxyString:
                return(_re_ProxyString.Value);

            case RegexType.PatreonCid:
                return(new Regex(_regex_PatreonCid, RegexOptions.Compiled));

            case RegexType.PatreonEmail:
                return(new Regex(_regex_PatreonEmail, RegexOptions.Compiled));

            case RegexType.PatreonHtmlImg:
                return(new Regex(_regex_PatreonHtmlImg, RegexOptions.Compiled));

            case RegexType.FanboxUrl1:
                return(new Regex(_regex_FanboxUrl1, RegexOptions.Compiled));

            case RegexType.FanboxUrl2:
                return(new Regex(_regex_FanboxUrl2, RegexOptions.Compiled));

            case RegexType.FanboxCSRF:
                return(new Regex(_regex_FanboxCSRF, RegexOptions.Compiled));

            case RegexType.FantiaIdName:
                return(new Regex(_regex_FantiaIdName, RegexOptions.Compiled));

            case RegexType.FantiaPlan:
                return(new Regex(_regex_FantiaPlan, RegexOptions.Compiled));

            case RegexType.FantiaPostId:
                return(new Regex(_regex_FantiaPostId, RegexOptions.Compiled));

            case RegexType.FantiaUrl:
                return(new Regex(_regex_FantiaUrl, RegexOptions.Compiled));

            case RegexType.FantiaDataImage:
                return(new Regex(_regex_FantiaDataImage, RegexOptions.Compiled));
            }
            return(null);
        }
Exemplo n.º 18
0
 public string this[RegexType regexType]
 {
     get
     {
         switch (regexType)
         {
             case RegexType.Ip:
                 return IpString;
             case RegexType.TelPhone:
                 return TelPhoneString;
             case RegexType.MobilePhone:
                 return MobilePhoneString;
             case RegexType.Email:
             default:
                 return EmailString;
         }
     }
 }
Exemplo n.º 19
0
        public SchemaRegex(string pattern, RegexType type = RegexType.Normal)
        {
            Pattern = pattern;
            Type    = type;

            if (type == RegexType.Normal)
            {
                try
                {
                    RegularExpression = new Regex(pattern,
                                                  RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.Singleline,
                                                  TimeSpan.FromMilliseconds(TimeLimitMs));
                }
                catch
                {
                    Type = RegexType.FaultedInvalid;
                }
            }
        }
Exemplo n.º 20
0
        public static Regex GetRegex(RegexType rt)
        {
            switch (rt)
            {
            case RegexType.RemoveLastDot:
                return(_re_RemoveLastDot.Value);

            case RegexType.ProxyString:
                return(_re_ProxyString.Value);

            case RegexType.PatreonCid:
                return(new Regex(_regex_PatreonCid));

            case RegexType.PatreonEmail:
                return(new Regex(_regex_PatreonEmail));

            case RegexType.PatreonHtmlImg:
                return(new Regex(_regex_PatreonHtmlImg));

            case RegexType.FanboxUrl1:
                return(new Regex(_regex_FanboxUrl1));

            case RegexType.FanboxUrl2:
                return(new Regex(_regex_FanboxUrl2));

            case RegexType.FanboxCSRF:
                return(new Regex(_regex_FanboxCSRF));

            case RegexType.FantiaIdName:
                return(new Regex(_regex_FantiaIdName));

            case RegexType.FantiaPlan:
                return(new Regex(_regex_FantiaPlan));

            case RegexType.FantiaPostId:
                return(new Regex(_regex_FantiaPostId));

            case RegexType.FantiaUrl:
                return(new Regex(_regex_FantiaUrl));
            }
            return(null);
        }
Exemplo n.º 21
0
        private List <ActiveItem> RegexDeclaration(string text, string pattern, RegexType type)
        {
            var listOfItems = new List <ActiveItem>();

            if (!string.IsNullOrEmpty(text))
            {
                var regex = new Regex(pattern);

                var items = regex.Matches(text).Cast <Match>().ToList();;

                foreach (var item in items)
                {
                    var startIndex = item.Index;
                    var lastIndex  = item.Index + item.Length;

                    listOfItems.Add(new ActiveItem(item.Value, type, startIndex, lastIndex));
                }
            }

            return(listOfItems);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 判断是否符合验证表达式
        /// </summary>
        /// <param name="regtype">验证类型</param>
        /// <param name="txt">验证值</param>
        /// <param name="isNull">是否允许为空</param>
        /// <returns></returns>
        public static bool IsMatch(RegexType regtype, string txt, bool isNull)
        {
            if (isNull && txt.Length == 0)
            {
                return(true);
            }

            //如果缓存中不存在验证表达式,那就将验证表达式添加到缓存中
            try
            {
                bool checktype = bool.Parse(cache["CheckType"].ToString());
            }
            catch
            {
                cache.Insert(RegexType.Email.ToString(), emial);
                cache.Insert(RegexType.Chinese.ToString(), chinese);
                cache.Insert(RegexType.Currency.ToString(), currency);
                cache.Insert(RegexType.Double.ToString(), doubles);
                cache.Insert(RegexType.English.ToString(), english);
                cache.Insert(RegexType.IdCart.ToString(), idcart);
                cache.Insert(RegexType.Integer.ToString(), integer);
                cache.Insert(RegexType.Mobile.ToString(), mobile);
                cache.Insert(RegexType.Number.ToString(), number);
                cache.Insert(RegexType.Phone.ToString(), phone);
                cache.Insert(RegexType.QQ.ToString(), qq);
                cache.Insert(RegexType.UnSafe.ToString(), unsafes);
                cache.Insert(RegexType.Url.ToString(), url);
                cache.Insert(RegexType.Zip.ToString(), zip);
                cache.Insert("CheckType", true);
            }
            bool ismat = false;

            //从缓存中获取表达式
            reg   = new Regex(cache[regtype.ToString()].ToString());
            ismat = reg.IsMatch(txt);
            reg   = null;
            return(ismat);
        }
Exemplo n.º 23
0
        public static Regex GetRegex(this RegexType t)
        {
            switch (t)
            {
            case RegexType.Rip:
                return(DirRegex.RipRegex);

            case RegexType.Quality:
                return(DirRegex.QRegex);

            case RegexType.Year:
                return(DirRegex.YearRegex);

            case RegexType.Time:
                return(DirRegex.TimeRegex);

            case RegexType.Foreign:
                return(DirRegex.ForeignRegex);

            default:
                throw new ArgumentOutOfRangeException(nameof(t), t, null);
            }
        }
Exemplo n.º 24
0
        public override bool NeedUpdate(RegexType type, string pattern, RegexOptions options)
        {
            bool isSameType = false;

            switch (type)
            {
            case RegexType.IsMatch:
            case RegexType.Match:
            case RegexType.Matches:
                isSameType = true;
                break;

            default:
                isSameType = false;
                break;
            }

            bool isSamePattern = (pattern == this.Pattern);

            bool isSameOptions = (this.regex == null) ? false : (options == this.regex.Options);

            return(!(isSamePattern && isSameType && isSameOptions));
        }
Exemplo n.º 25
0
        private void showErrorMessage(RegexType value)
        {
            switch (value)
            {
            case RegexType.Number:
                errorMessage = "只能输入数字!";
                break;

            case RegexType.Zip:
                errorMessage = "输入的邮政编码不合法";
                break;

            case RegexType.Email:
                errorMessage = "输入的邮件地址不合法";
                break;

            case RegexType.Phone:
                errorMessage = "输入的电话号码不合法";
                break;

            case RegexType.Float:
                errorMessage = "输入的金额不合法";
                break;

            case RegexType.MixChar:
                errorMessage = "只能输入半角英文或者数字";
                break;

            case RegexType.Date:
                errorMessage = "输入的日期格式不正确,应该为yyyyMMdd,例如20010101";
                break;

            case RegexType.YearMonth:
                errorMessage = "输入的日期格式不正确,应该为yyyyMM,例如200101";
                break;
            }
        }
Exemplo n.º 26
0
 public static bool Test(string value, RegexType regexType)
 {
     return(Regex.IsMatch(value, GetRegexItem(regexType).RegexString));
 }
 public static bool ValidText(string text, RegexType regexType)
 {
     return(GetRegexByRegexType(regexType).IsMatch(text));
 }
Exemplo n.º 28
0
        private bool Invalid(RegexType value, string text)
        {
            bool b = false;

            switch (value)
            {
            case RegexType.Custom:
                b = true;
                break;

            case RegexType.Number:
                b = Validation(text, @"^\d+$");
                break;

            case RegexType.CNString:
                b = Validation(text, @"^[\u4e00-\u9fa5]$");
                break;

            case RegexType.Zip:
                b = Validation(text, @"^[1-9]\d{5}$");
                break;

            case RegexType.Email:
                b = Validation(text, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
                break;

            case RegexType.Phone:
                b = Validation(text, @"^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$");
                break;

            case RegexType.CNPhone:
                b = Validation(text, @"^\d{3}-\d{8}|\d{4}-\d{7}$");
                break;

            case RegexType.Mobile:
                b = Validation(text, @"^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$");
                break;

            case RegexType.Integer:
                b = Validation(text, @"^-?\d+$");
                break;

            case RegexType.NInteger:
                b = Validation(text, @"^-[0-9]*[1-9][0-9]*$");
                break;

            case RegexType.Float:
                b = Validation(text, @"^(-?\d+)(\.\d+)?$");
                break;

            case RegexType.NNFloat:
                b = Validation(text, @"^\d+(\.\d+)?$");
                break;

            case RegexType.PFloat:
                b = Validation(text, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
                break;

            case RegexType.NPFloat:
                b = Validation(text, @"^((-\d+(\.\d+)?)|(0+(\.0+)?))$");
                break;

            case RegexType.NFloat:
                b = Validation(text, @"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$");
                break;

            case RegexType.ENChar:
                b = Validation(text, @"^[A-Za-z]+$");
                break;

            case RegexType.ENUChar:
                b = Validation(text, @"^[A-Z]+$");
                break;

            case RegexType.ENLChar:
                b = Validation(text, @"^[a-z]+$");
                break;

            case RegexType.MixChar:
                b = Validation(text, @"^[A-Za-z0-9]+$");
                break;

            case RegexType.MixLineChar:
                b = Validation(text, @"^\w+$");
                break;

            case RegexType.Url:
                b = Validation(text, @"^(?:https?|ftp)\:\/\/(?:(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=:]|%[0-9a-f]{2,2})*\@)?(?:((?:(?:[a-z0-9][a-z0-9\-]*[a-z0-9]|[a-z0-9])\.)*(?:[a-z][a-z0-9\-]*[a-z0-9]|[a-z])|(?:\[[^\]]*\]))(?:\:[0-9]*)?)(?:\/(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=\:\@]|%[0-9a-f]{2,2})*)*(?:\?(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=\:\@\/\?]|%[0-9a-f]{2,2})*)?(?:\#(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=\:\@\/\?]|%[0-9a-f]{2,2})*)?$");
                break;

            case RegexType.QQ:
                b = Validation(text, @"^[1-9][0-9]{4,}$");
                break;

            case RegexType.DCard:
                b = Validation(text, @"^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|71|(8[12])|91)\d{4}((19\d{2}(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(19\d{2}(0[13578]|1[02])31)|(19\d{2}02(0[1-9]|1\d|2[0-8]))|(19([13579][26]|[2468][048]|0[48])0229))\d{3}(\d|X|x)?$");
                break;

            case RegexType.IP:
                b = Validation(text, @"^(\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])$");
                break;

            case RegexType.DateTime:
                b = Validation(text, @"^((((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-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$");
                break;

            case RegexType.Date:
                b = Validation(text, @"^((((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-))$");
                break;

            case RegexType.Year:
                b = Validation(text, @"^((1[6-9]|[2-9]\d)\d{2})$");
                break;

            case RegexType.Month:
                b = Validation(text, @"^(0?[123456789]|1[012])$");
                break;

            case RegexType.Day:
                b = Validation(text, @"^(0?[1-9]|[12]\d|3[01])$");
                break;

            case RegexType.Time:
                b = Validation(text, @"^(20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$");
                break;

            case RegexType.DateTimeAm:
                b = Validation(text, @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$");
                break;

            case RegexType.Date2:
                b = Validation(text, @"^((((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日))$");
                break;
            }
            return(b);
        }
Exemplo n.º 29
0
 private bool Invalid(RegexType value, string text)
 {
     bool b = false;
     switch (value)
     {
         case RegexType.Custom:
             b = true;
             break;
         case RegexType.Number:
             b = Validation(text, @"^\d+$");
             break;
         case RegexType.CNString:
             b = Validation(text, @"^[\u4e00-\u9fa5]$");
             break;
         case RegexType.Zip:
             b = Validation(text, @"^[1-9]\d{5}$");
             break;
         case RegexType.Email:
             b = Validation(text, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
             break;
         case RegexType.Phone:
             b = Validation(text, @"^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$");
             break;
         case RegexType.CNPhone:
             b = Validation(text, @"^\d{3}-\d{8}|\d{4}-\d{7}$");
             break;
         case RegexType.Mobile:
             b = Validation(text, @"^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$");
             break;
         case RegexType.Integer:
             b = Validation(text, @"^-?\d+$");
             break;
         case RegexType.NInteger:
             b = Validation(text, @"^-[0-9]*[1-9][0-9]*$");
             break;
         case RegexType.Float:
             b = Validation(text, @"^(-?\d+)(\.\d+)?$");
             break;
         case RegexType.NNFloat:
             b = Validation(text, @"^\d+(\.\d+)?$");
             break;
         case RegexType.PFloat:
             b = Validation(text, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
             break;
         case RegexType.NPFloat:
             b = Validation(text, @"^((-\d+(\.\d+)?)|(0+(\.0+)?))$");
             break;
         case RegexType.NFloat:
             b = Validation(text, @"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$");
             break;
         case RegexType.ENChar:
             b = Validation(text, @"^[A-Za-z]+$");
             break;
         case RegexType.ENUChar:
             b = Validation(text, @"^[A-Z]+$");
             break;
         case RegexType.ENLChar:
             b = Validation(text, @"^[a-z]+$");
             break;
         case RegexType.MixChar:
             b = Validation(text, @"^[A-Za-z0-9]+$");
             break;
         case RegexType.MixLineChar:
             b = Validation(text, @"^\w+$");
             break;
         case RegexType.Url:
             b = Validation(text, @"^(?:https?|ftp)\:\/\/(?:(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=:]|%[0-9a-f]{2,2})*\@)?(?:((?:(?:[a-z0-9][a-z0-9\-]*[a-z0-9]|[a-z0-9])\.)*(?:[a-z][a-z0-9\-]*[a-z0-9]|[a-z])|(?:\[[^\]]*\]))(?:\:[0-9]*)?)(?:\/(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=\:\@]|%[0-9a-f]{2,2})*)*(?:\?(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=\:\@\/\?]|%[0-9a-f]{2,2})*)?(?:\#(?:[a-z0-9\-\._~\!\$\&\'\(\)\*\+\,\;\=\:\@\/\?]|%[0-9a-f]{2,2})*)?$");
             break;
         case RegexType.QQ:
             b = Validation(text, @"^[1-9][0-9]{4,}$");
             break;
         case RegexType.DCard:
             b = Validation(text, @"^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|71|(8[12])|91)\d{4}((19\d{2}(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(19\d{2}(0[13578]|1[02])31)|(19\d{2}02(0[1-9]|1\d|2[0-8]))|(19([13579][26]|[2468][048]|0[48])0229))\d{3}(\d|X|x)?$");
             break;
         case RegexType.IP:
             b = Validation(text, @"^(\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])$");
             break;
         case RegexType.DateTime:
             b = Validation(text, @"^((((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-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$");
             break;
         case RegexType.Date:
             b = Validation(text, @"^((((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-))$");
             break;
         case RegexType.Year:
             b = Validation(text, @"^((1[6-9]|[2-9]\d)\d{2})$");
             break;
         case RegexType.Month:
             b = Validation(text, @"^(0?[123456789]|1[012])$");
             break;
         case RegexType.Day:
             b = Validation(text, @"^(0?[1-9]|[12]\d|3[01])$");
             break;
         case RegexType.Time:
             b = Validation(text, @"^(20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$");
             break;
         case RegexType.DateTimeAm:
             b = Validation(text, @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$");
             break;
         case RegexType.Date2:
             b = Validation(text, @"^((((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日))$");
             break;
     }
     return b;
 }
Exemplo n.º 30
0
 public void SetRegexType(RegexType type)
 {
     this.Type = type;
     this.UpdateRegex();
 }
Exemplo n.º 31
0
        /// <summary>
        /// 对数据进行处理
        /// by XP-PC 2012/4/23
        /// </summary>
        /// <param name="regexType">正则表达式的类型.</param>
        /// <param name="data">待替换的数据.</param>
        /// <param name="dataValue">用于替换的值对象,可以支持Dictionary (string object)  Hashtable DataRow.</param>
        /// <param name="repNull">是否把不存在的字段替换为空.</param>
        /// <returns>
        /// System.String
        /// </returns>
        public static string ReplaceData(RegexType regexType, string data, object dataValue, bool repNull)
        {
            //待处理数据为空时直接返回空字符
            if (data == null)
            {
                return(string.Empty);
            }
            Regex regex = RuleRegex.BraceExternal;

            if (regexType == RegexType.Bracket)
            {
                regex = RuleRegex.BracketExternal;
            }
            //
            StringBuilder sb = new StringBuilder(data);

            try
            {
                bool isNull = repNull && dataValue == null;
                for (Match m = regex.Match(sb.ToString()); m.Success; m = m.NextMatch()) //处理普通模板
                {
                    string regval     = m.Groups["Name"].Value;
                    string expression = m.Groups["External"].Value;
                    if (isNull)
                    {
                        sb.Replace(m.ToString(), "");
                    }
                    else
                    {
                        object val = null;
                        if (dataValue is Dictionary <string, object> )
                        {
                            Dictionary <string, object> vic = (Dictionary <string, object>)dataValue;
                            if (vic.ContainsKey(regval))
                            {
                                val = vic[regval];
                            }
                        }
                        else if (dataValue is DataRow)
                        {
                            DataRow dr = (DataRow)dataValue;
                            if (dr.Table.Columns.Contains(regval))
                            {
                                val = dr[regval];
                            }
                        }
                        else if (dataValue is Hashtable)
                        {
                            Hashtable ht = (Hashtable)dataValue;
                            if (ht.ContainsKey(regval))
                            {
                                val = ht[regval];
                            }
                        }
                        if (val == null)
                        {
                            if (repNull)
                            {
                                sb.Replace(m.ToString(), "");
                            }
                        }
                        else
                        {
                            sb.Replace(m.Value, FormatUtil.Formater(expression, val));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //new ECFException(ex.Message, ex);
            }
            return(sb.ToString());
        }
Exemplo n.º 32
0
        public async Task <ActionResult <Book> > CreateBook()
        {
            var book = new Book()
            {
                ChapterCount = 1,
                LastUpdate   = DateTime.Now,
                Name         = "HPMOR",
                IndexURL     = "https://m.fanfiction.net/s/5782108/1/Harry-Potter-and-the-Methods-of-Rationality",
                ChapterURL   = "https://m.fanfiction.net/s/5782108/{0}/Harry-Potter-and-the-Methods-of-Rationality"
            };

            _context.Books.Add(book);
            _context.SaveChanges();

            var bookTemplate = new BookTemplate()
            {
                Book    = book,
                Header  = "{0}",
                Chapter = "<html><head><title>Chapter!</title></head><body>{0}</body></html>",
                Footer  = "{0}"
            };

            _context.BookTemplates.Add(bookTemplate);
            _context.SaveChanges();

            var CountType = new RegexType()
            {
                Name        = RegexTypes.ChapterCount.ToString(),
                Description = ""
            };

            _context.RegexTypes.Add(CountType);
            _context.SaveChanges();

            var TitleType = new RegexType()
            {
                Name        = RegexTypes.ChapterTitle.ToString(),
                Description = ""
            };

            _context.RegexTypes.Add(TitleType);
            _context.SaveChanges();

            var ContentType = new RegexType()
            {
                Name        = RegexTypes.ChapterContent.ToString(),
                Description = ""
            };

            _context.RegexTypes.Add(ContentType);
            _context.SaveChanges();

            var regex = new Database.Tables.Regex()
            {
                Book        = book,
                RegexString = "Ch 1 of <a href=\'/s/5782108/[0-9]+/\'>([0-9]+)</a",
                Type        = CountType,
            };

            _context.Regexes.Add(regex);

            var regex2 = new Database.Tables.Regex()
            {
                Book        = book,
                RegexString = "(Chapter .+?)<br></div>",
                Type        = TitleType,
            };

            _context.Regexes.Add(regex2);

            var regex3 = new Database.Tables.Regex()
            {
                Book        = book,
                RegexString = "<div style='.+?' class='storycontent nocopy' id='storycontent' >(.+?)<div align=center>",
                Type        = ContentType,
            };

            _context.Regexes.Add(regex3);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBook", new { id = book.Id }, book));
        }
Exemplo n.º 33
0
 private void ShowDescription(RegexType value)
 {
     switch (value)
     {
         case RegexType.Custom:
             this._controlTypeText = "默认";
             break;
         case RegexType.Number:
             this._controlTypeText = "数字";
             break;
         case RegexType.CNString:
             this._controlTypeText = "汉字";
             break;
         case RegexType.Zip:
             this._controlTypeText = "邮政编码";
             break;
         case RegexType.Email:
             this._controlTypeText = "电子邮件";
             break;
         case RegexType.Phone:
             this._controlTypeText = "座机电话号码";
             break;
         case RegexType.CNPhone:
             this._controlTypeText = "中国电话号码";
             break;
         case RegexType.Mobile:
             this._controlTypeText = "手机号码";
             break;
         case RegexType.Integer:
             this._controlTypeText = "整数";
             break;
         case RegexType.NInteger:
             this._controlTypeText = "负整数";
             break;
         case RegexType.Float:
             this._controlTypeText = "浮点数";
             break;
         case RegexType.NNFloat:
             this._controlTypeText = "非负浮点数";
             break;
         case RegexType.PFloat:
             this._controlTypeText = "正浮点数";
             break;
         case RegexType.NPFloat:
             this._controlTypeText = "非正浮点数";
             break;
         case RegexType.NFloat:
             this._controlTypeText = "负浮点数";
             break;
         case RegexType.ENChar:
             this._controlTypeText = "英文字符";
             break;
         case RegexType.ENUChar:
             this._controlTypeText = "大写英文字符";
             break;
         case RegexType.ENLChar:
             this._controlTypeText = "小写英文字符";
             break;
         case RegexType.MixChar:
             this._controlTypeText = "数字和英文字母";
             break;
         case RegexType.MixLineChar:
             this._controlTypeText = "数字、英文字母或下划线";
             break;
         case RegexType.Url:
             this._controlTypeText = "URL";
             break;
         case RegexType.QQ:
             this._controlTypeText = "QQ";
             break;
         case RegexType.DCard:
             this._controlTypeText = "身份证";
             break;
         case RegexType.IP:
             this._controlTypeText = "IP";
             break;
         case RegexType.DateTime:
             this._controlTypeText = "2000-2-28 23:29:59";
             break;
         case RegexType.Date:
             this._controlTypeText = "2000-2-28";
             break;
         case RegexType.Year:
             this._controlTypeText = "年份";
             break;
         case RegexType.Month:
             this._controlTypeText = "月份";
             break;
         case RegexType.Day:
             this._controlTypeText = "日";
             break;
         case RegexType.Time:
             this._controlTypeText = "23:29:59";
             break;
         case RegexType.DateTimeAm:
             this._controlTypeText = "2000-02-29 10:29:39 pm";
             break;
         case RegexType.Date2:
             this._controlTypeText = "2009年2月28日";
             break;
     }
 }
 public static string GetMatch(string text, RegexType regexType)
 {
     return(GetRegexByRegexType(regexType).Match(text).Groups[1].Value);
 }