Пример #1
0
        private string FormatMessage(IValidatorConfig config, string message, int?val)
        {
            var text      = string.IsNullOrEmpty(config.Message) ? message : config.Message;
            var fieldName = string.IsNullOrEmpty(config.FieldCaption) ? config.FieldCode : config.FieldCaption;

            return(val == null?string.Format(text, fieldName) : string.Format(text, fieldName, val));
        }
Пример #2
0
        public List <IFieldValidationInfo> Validate(IValidatorConfig config)
        {
            var result = new List <IFieldValidationInfo>();

            if (config.Value == null)
            {
                var message = string.Format(Resources.Error_Empty_Field, config.FieldCode);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));

                return(result);
            }

            string value = config.Value as string;

            var regex    = new Regex(pattern, options);
            var hasMatch = regex.IsMatch(value);

            if (!hasMatch)
            {
                result.Add(new FieldValidationInfo(config.FieldCode, error_NoMatch, ErrorLevel.Critical));
            }

            return(result);
        }
Пример #3
0
        private List <IFieldValidationInfo> ValidateMinLenght(IValidatorConfig config)
        {
            var result = new List <IFieldValidationInfo>();

            if (config.Value.ToString().Length < ConstMinLenght)
            {
                result.Add(new FieldValidationInfo(config.FieldCode, Resources.Error_Pswd_Lenght, ErrorLevel.Critical));
            }

            return(result);
        }
Пример #4
0
        private List <IFieldValidationInfo> ValidateEmpty(IValidatorConfig config)
        {
            var result = new List <IFieldValidationInfo>();

            if (string.IsNullOrEmpty(config.Value.ToString()))
            {
                var text      = string.IsNullOrEmpty(config.Message) ? Resources.Error_Empty_Field : config.Message;
                var fieldName = string.IsNullOrEmpty(config.FieldCaption) ? config.FieldCode : config.FieldCaption;
                var message   = string.Format(text, fieldName);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));
            }

            return(result);
        }
Пример #5
0
        public List <IFieldValidationInfo> Validate(IValidatorConfig config)
        {
            var cfg = config as StringValidatorConfig;

            var result = new List <IFieldValidationInfo>();

            if (cfg.Value == null)
            {
                var message = FormatMessage(config, Resources.Error_Empty_Field, null);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));

                return(result);
            }

            result.AddRange(ValidateMinLenght(cfg));

            return(result);
        }
Пример #6
0
        public List <IFieldValidationInfo> Validate(IValidatorConfig config)
        {
            var result = new List <IFieldValidationInfo>();

            if (config.Value == null)
            {
                var text      = string.IsNullOrEmpty(config.Message) ? Resources.Error_Empty_Field : config.Message;
                var fieldName = string.IsNullOrEmpty(config.FieldCaption) ? config.FieldCode : config.FieldCaption;
                var message   = string.Format(text, fieldName);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));

                return(result);
            }

            result.AddRange(ValidateEmpty(config));
            result.AddRange(ValidateMinLenght(config));
            result.AddRange(ValidateRegex(config));

            return(result);
        }
Пример #7
0
        public List <IFieldValidationInfo> Validate(IValidatorConfig config)
        {
            var result = new List <IFieldValidationInfo>();

            var cfg = config as RangeValidatorConfig;

            if (cfg.Min <= 0 && cfg.Max <= 0)
            {
                return(result);
            }

            if (config.Value == null)
            {
                var message = FormatMessage(config, Resources.Error_Empty_Field, null);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));

                return(result);
            }

            var value = config.Value is int?(int)config.Value : 0;

            if (cfg.Min > 0 && value < cfg.Min)
            {
                var message = FormatMessage(config, Resources.Error_Range_Min, cfg.Min);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));
            }

            if (cfg.Max > 0 && value > cfg.Max)
            {
                var message = FormatMessage(config, Resources.Error_Range_Max, cfg.Max);

                result.Add(new FieldValidationInfo(config.FieldCode, message, ErrorLevel.Critical));
            }

            return(result);
        }
Пример #8
0
        private List <IFieldValidationInfo> ValidateRegex(IValidatorConfig config)
        {
            var result = new List <IFieldValidationInfo>();
            var value  = config.Value.ToString();

            var regexmatchLowCase   = Regex.IsMatch(value, RegexSymbolsLowcase);
            var regexmatchUpperCase = Regex.IsMatch(value, RegexSymbolsUppercase);
            var regexmatchNumber    = Regex.IsMatch(value, RegexNumbers);

            if (!regexmatchLowCase && !regexmatchUpperCase)
            {
                result.Add(new FieldValidationInfo(config.FieldCode, Resources.Error_Pswd_UpperLowCase,
                                                   ErrorLevel.Critical));
            }

            if (!regexmatchNumber)
            {
                result.Add(new FieldValidationInfo(config.FieldCode, Resources.Error_Pswd_Numbers,
                                                   ErrorLevel.Critical));
            }

            return(result);
        }