Ejemplo n.º 1
0
        private void Validate(ValidatorResult result, T entity, ValidationTypes type)
        {
            switch (type)
            {
            case ValidationTypes.Default:
                DefaultValidations(result, entity);
                break;

            case ValidationTypes.Insert:
                InsertValidations(result, entity);
                break;

            case ValidationTypes.Update:
                UpdateValidations(result, entity);
                break;

            case ValidationTypes.Delete:
                DeleteValidations(result, entity);
                break;

            default:
                DefaultValidations(result, entity);
                break;
            }
        }
Ejemplo n.º 2
0
 public Validatable(T initialValue, ValidationTypes validationType, Func <Task <bool> > validatorAsync)
 {
     this.myValue          = initialValue;
     this.myLastValidValue = initialValue;
     this.ValidationType   = validationType;
     this.ValidatorAsync   = validatorAsync;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates an object validation.
 /// </summary>
 /// <param name="message">The message associated with the validation.</param>
 /// <param name="validationType">The object properties pertaining to the validation.</param>
 public ValidationItem(
     string message,
     ValidationTypes validationType)
 {
     Message        = message ?? throw new ArgumentNullException(nameof(message));
     ValidationType = validationType;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates an object validation.
 /// </summary>
 /// <param name="message">The message associated with the validation.</param>
 /// <param name="propertyNames">The object properties pertaining to the validation.</param>
 public ValidationItem(
     string message,
     ValidationTypes validationType)
 {
     this.Message        = message;
     this.ValidationType = validationType;
 }
        /// <summary>
        /// This method must also *restore* a decimal and trailing zeroes when first focused.
        /// </summary>
        public static string StripStringFormatCharacters(string entryText,
                                                         string stringFormat,
                                                         ValidationTypes validationType,
                                                         int charsToRight  = 0,
                                                         bool firstFocused = false)
        {
            // Remove the numeric string formats (all except for numbers and dots)
            if (stringFormat.IsEmpty() || entryText.IsEmpty())
            {
                return(entryText);
            }

            // Numbers are either "Whole" (no special symbols allowed) or "Decimal" (a single dot is allowed, plus a certain
            // number of characters after that).
            switch (validationType)
            {
            case ValidationTypes.DecimalNumber:
                var retString = Regex.Replace(entryText, "[^0-9.]+", "");

                // Add the period and zeroes
                if (firstFocused)
                {
                    var decimalPos = retString.PositionOfDecimal();
                    if (decimalPos == -1)
                    {
                        retString += Extensions.DECIMAL;
                        decimalPos = retString.PositionOfDecimal();
                    }

                    var trueEndPos = decimalPos + charsToRight;
                    for (var charIdx = decimalPos + 1; charIdx <= trueEndPos; charIdx++)
                    {
                        // char idx of 2 with ret string length of 2 means that retString[2] doesn't yet exist.
                        if (charIdx >= retString.Length)
                        {
                            retString += "0";
                        }
                    }
                }

                return(retString);

            case ValidationTypes.WholeNumber:

                //entryText = entryText.StripLeadingZeroes();
                //entryText = entryText.StripTrailingNumbers(_maxDecimalChars);

                return(Regex.Replace(entryText, "[^0-9]+", ""));

            default:

                // Illegal
                Debug.WriteLine(nameof(NumericEntryValidationBehavior) + ": " + nameof(PrepareTextForEditing) +
                                ": illegal numeric validation type ->" + validationType + "<-");
                break;
            }

            return(entryText);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Validates string against ValidationType
        ///
        /// If the text does not match the ValidationType then an error is raised
        /// </summary>
        /// <param name="validationText">string to validate</param>
        /// <param name="validationType">type of validation</param>
        /// <returns>Validated string</returns>
        public static string Validate(string validationText, ValidationTypes validationType)
        {
            string Result = validationText;

            switch (validationType)
            {
            case ValidationTypes.AlphaNumeric:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_ALPHANUMERIC);

                break;

            case ValidationTypes.AtoZ:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_A_TO_Z);
                break;

            case ValidationTypes.CreditCard:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_NUMBER);
                CardType(Result);

                break;

            case ValidationTypes.IsNumeric:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_NUMBER);

                break;

            case ValidationTypes.Name:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_NAME);

                break;

            case ValidationTypes.CardValidFrom:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_CARD_DATE);
                CardDateValid(Result, false);

                break;

            case ValidationTypes.CardValidTo:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_CARD_DATE);
                CardDateValid(Result, true);
                break;

            case ValidationTypes.FileName:
                Result = RemoveInvalidChars(Result, ALLOWED_CHARS_FILENAME);

                break;

            default:
                throw new ArgumentException("Invalid ValidationType, or validationType not handled");
            }

            //assume if it's zero length then error
            if (String.IsNullOrEmpty(Result))
            {
                throw new FormatException(String.Format("{0} is not of type {1}", validationText, validationType));
            }

            return(Result);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns a validation result indicating that validation was not applied.
 /// </summary>
 /// <param name="rootObject">The root object.</param>
 /// <returns></returns>
 public static ValidationResultSet ValidResult(object rootObject)
 {
     return(new ValidationResultSet
     {
         RootObject = rootObject ?? throw new ArgumentNullException(nameof(rootObject)),
         ValidationType = ValidationTypes.Valid,
         ObjectValidations = new ObjectValidation[] { }
     });
Ejemplo n.º 8
0
 public bool Verify(bool predicate, string message, ValidationTypes level = ValidationTypes.Error, params string[] propertyNames)
 {
     if (!predicate)
     {
         _validations.Add(new ValidationItem(message, level));
     }
     return(predicate);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates an object containing validations associated with an object.
        /// </summary>
        /// <param name="obj">The validated object.</param>
        /// <param name="validations">The associated validations.</param>
        public ObjectValidation(object obj,
                                ValidationItem[] validations)
        {
            Object      = obj ?? throw new ArgumentNullException(nameof(obj));
            Validations = validations ?? throw new ArgumentNullException(nameof(validations));

            ValidationType = GetMaxValidationType();
        }
Ejemplo n.º 10
0
        public ValidatorResult Validate(T entity, ValidationTypes type = ValidationTypes.Default)
        {
            var result = new ValidatorResult();

            Validate(result, entity, type);

            return(result);
        }
Ejemplo n.º 11
0
 public void Add(ValidationTypes type, string error)
 {
     if (!string.IsNullOrWhiteSpace(error))
     {
         ErrorTypes |= type;
         errors.Add(error);
     }
 }
Ejemplo n.º 12
0
 public Result(string title, IPactInformation info, ValidationTypes types, params string[] errors)
 {
     this.errors   = errors.ToList();;
     ErrorTypes    = types;
     Title         = title;
     Description   = info.Description;
     Consumer      = info.Consumer;
     ProviderState = info.ProviderState;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates an object property validation.
 /// </summary>
 /// <param name="message">The message associated with the validation.</param>
 /// <param name="propertyNames">The object properties pertaining to the validation.</param>
 /// <param name="validationType">The validation level.</param>
 public ValidationItem(
     string message,
     IEnumerable <string> propertyNames,
     ValidationTypes validationType)
 {
     this.Message        = message;
     this.PropertyNames  = propertyNames;
     this.ValidationType = validationType;
 }
Ejemplo n.º 14
0
 public ValidationHandler(
     IValidationRequest request,
     ValidationTypes validationType,
     IHandler handler)
 {
     this.request        = request;
     this.next           = handler;
     this.validationType = validationType;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates an object property validation.
 /// </summary>
 /// <param name="message">The message associated with the validation.</param>
 /// <param name="propertyNames">The object properties pertaining to the validation.</param>
 /// <param name="validationType">The validation level.</param>
 public ValidationItem(
     string message,
     IEnumerable <string> propertyNames,
     ValidationTypes validationType)
 {
     Message        = message ?? throw new ArgumentNullException(nameof(message));
     PropertyNames  = propertyNames ?? throw new ArgumentNullException(nameof(propertyNames));
     ValidationType = validationType;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates an object containing validation associated with an object.
        /// </summary>
        /// <param name="obj">The validated object.</param>
        /// <param name="validations">The associated validations.</param>
        public ObjectValidation(object obj,
                                ValidationItem[] validations)
        {
            Check.NotNull(obj, nameof(obj));
            Check.NotNull(validations, nameof(validations));

            this.Object         = obj;
            this.Validations    = validations;
            this.ValidationType = GetMaxValidationType();
        }
Ejemplo n.º 17
0
 public void Add(ValidationTypes type, IEnumerable <string> errors)
 {
     if (errors != null)
     {
         foreach (var error in errors)
         {
             Add(type, error);
         }
     }
 }
Ejemplo n.º 18
0
        public bool Validate(bool predicate, string message,
                             ValidationTypes level = ValidationTypes.Error)
        {
            Check.NotNullOrWhiteSpace(message, nameof(message));

            if (!predicate)
            {
                _items.Add(new ValidationItem(message, level));
            }
            return(predicate);
        }
Ejemplo n.º 19
0
 public static bool Validate(string value, ValidationTypes validationTypes)
 {
     return(validationTypes switch
     {
         StringEmpty => ValidationMethods.StringEmptyValidation(value),
         EMail => ValidationMethods.EmailValidation(value),
         PhoneNumber => ValidationMethods.PhoneNumberValidation(value),
         Numeric => ValidationMethods.NumericValidation(value),
         _ => throw new ArgumentOutOfRangeException(nameof(validationTypes),
                                                    validationTypes, null)
     });
Ejemplo n.º 20
0
        public ValidatorResult Validate(T[] entities, ValidationTypes type = ValidationTypes.Default)
        {
            var result = new ValidatorResult();

            foreach (var entity in entities)
            {
                Validate(result, entity, type);
            }

            return(result);
        }
Ejemplo n.º 21
0
 public override void Cancel()
 {
     if (ObjectState == ObjectStates.Added)
     {
         ((ValidationConditions)Parent).InternalRemove(this);
     }
     else if (ObjectState != ObjectStates.None)
     {
         _qualifier       = OriginalValues._qualifier;
         _validationType  = OriginalValues._validationType;
         _validationValue = OriginalValues._validationValue;
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates new instance representing a validation result.
        /// </summary>
        /// <param name="rootObject">The root object that was validated.</param>
        /// <param name="validator">The validator used to validated the object.</param>
        public ValidationResult(object rootObject, IObjectValidator validator)
        {
            Check.NotNull(rootObject, nameof(rootObject));
            Check.NotNull(validator, nameof(validator));

            this.RootObject = rootObject;

            var validations = new List <ObjectValidation>();

            BuildValidationList(validations, validator);

            this.ValidationType    = GetMaxValidationType(validations);
            this.ObjectValidations = validations.ToArray();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates new instance representing a validation result.
        /// </summary>
        /// <param name="rootObject">The root object that was validated.</param>
        /// <param name="validator">The validator used to validated the object.</param>
        public ValidationResultSet(object rootObject, IObjectValidator validator)
        {
            RootObject = rootObject ?? throw new ArgumentNullException(nameof(rootObject));

            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }

            var validations = new List <ObjectValidation>();

            BuildValidationList(validations, validator);

            ObjectValidations = validations.ToArray();
            ValidationType    = GetMaxValidationType(ObjectValidations);
        }
Ejemplo n.º 24
0
        public bool Verify(bool predicate, string message,
                           ValidationTypes level = ValidationTypes.Error,
                           params string[] propertyNames)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message),
                                                "Message cannot be null or empty string.");
            }

            if (!predicate)
            {
                _items.Add(new ValidationItem(message, propertyNames, level));
            }
            return(predicate);
        }
Ejemplo n.º 25
0
        private static void Txt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            if (!(sender is DependencyObject))
            {
                return;
            }
            ValidationTypes selectedValiation = GetValidationType(sender as DependencyObject);

            if (selectedValiation == ValidationTypes.None)
            {
                return;
            }
            var str = new StringEnumeration(typeof(ValidationTypes));

            e.Handled = IsValidData(e.Text,
                                    str.GetStringValue(Enum.GetName(typeof(ValidationTypes), selectedValiation)));
            var textBox = sender as TextBox;

            if (textBox == null)
            {
                return;
            }
            try
            {
                if (selectedValiation == ValidationTypes.Decimal)
                {
                    if (e.Text == ".")
                    {
                        int previousCaretIndex = textBox.CaretIndex;
                        textBox.Text       = !textBox.Text.Contains(".") ? string.Format("{0}.0", textBox.Text) : textBox.Text;
                        textBox.CaretIndex = previousCaretIndex + 1;
                    }
                    e.Handled =
                        IsValidNumberData(textBox.Text.Insert(textBox.CaretIndex, e.Text),
                                          @"^-?\d*\.?\d{0," + GetDecimalNumbers(sender as DependencyObject) + "}?$");
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            if (selectedValiation == ValidationTypes.Numeric)
            {
                e.Handled =
                    IsValidNumberData(textBox.Text.Insert(textBox.CaretIndex, e.Text), @"^\d*$");
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Adds a value to the form values collection so it will be validated
        /// </summary>
        /// <param name="formValue">Value entered in the html "name" attribute of the form element being validated.</param>
        /// <param name="dataType">Type of validation to be preformed on the form value. Value comes from the "ValidationTypes" enumeration.</param>
        /// <param name="valueName">Text name that will be outputted in any validation error that occurs.</param>
        /// <param name="required">Boolean value determining if this value is required. If the value is required it cannot be left blank. If it is not required an empty string can be entered.</param>
        public void AddValue(string formValue, ValidationTypes dataType, string valueName, bool required)
        {
            object[] newRequiredValue = new object[4];
            object[] newValue         = new object[4];

            // if the field is required add a default existance check
            if (required && dataType != ValidationTypes.Existence)
            {
                newRequiredValue[0] = formValue;
                newRequiredValue[1] = ValidationTypes.Existence;
                newRequiredValue[2] = valueName;
                newRequiredValue[3] = required;
            }

            // create a static array and add it to the array list
            newValue[0] = formValue;
            newValue[1] = dataType;
            newValue[2] = valueName;
            newValue[3] = required;

            mFormValues.Add(newValue);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Adds a value to the form values collection so it will be validated
        /// </summary>
        /// <param name="formValue">Value entered in the html "name" attribute of the form element being validated.</param>
        /// <param name="dataType">Type of validation to be preformed on the form value. Value comes from the "ValidationTypes" enumeration.</param>
        /// <param name="valueName">Text name that will be outputted in any validation error that occurs.</param>
        /// <param name="required">Boolean value determining if this value is required. If the value is required it cannot be left blank. If it is not required an empty string can be entered.</param>
        public void AddValue(string formValue, ValidationTypes dataType, string valueName, bool required)
        {
            object[] newRequiredValue = new object[4];
            object[] newValue = new object[4];

            // if the field is required add a default existance check
            if (required && dataType != ValidationTypes.Existence)
            {
                newRequiredValue[0] = formValue;
                newRequiredValue[1] = ValidationTypes.Existence;
                newRequiredValue[2] = valueName;
                newRequiredValue[3] = required;
            }

            // create a static array and add it to the array list
            newValue[0] = formValue;
            newValue[1] = dataType;
            newValue[2] = valueName;
            newValue[3] = required;

            mFormValues.Add(newValue);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Returns all object validations containing validation items of a specific type.
 /// </summary>
 /// <param name="validationType">The validation type.</param>
 /// <returns>List of object validations containing validation items of a matching type.</returns>
 public IEnumerable <ObjectValidation> GetValidationsOfType(ValidationTypes validationType)
 {
     return(ObjectValidations.Where(ov =>
                                    ov.Validations.Any(v => v.ValidationType == validationType)));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Creates a new instance of frmInputBox
 /// </summary>
 /// <param name="owner">Specifies the Form to set as the owner of this dialog.</param>
 /// <param name="text">The string message to show.</param>
 /// <param name="caption">The string caption to allow.</param>
 /// <param name="validation">A MapWindow.Main.ValidationType enumeration specifying acceptable validation to return OK.</param>
 /// <param name="icon">Specifies an icon to appear on this messagebox.</param>
 public InputBox(Form owner, string text, string caption, ValidationTypes validation, Icon icon)
     : this()
 {
     this.Owner = owner;
     _validation = validation;
     lblMessageText.Text = text;
     Text = caption;
     ShowIcon = true;
     Icon = icon;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Creates a new instance of frmInputBox
 /// </summary>
 /// <param name="text">The string message to show.</param>
 /// <param name="caption">The string caption to allow.</param>
 /// <param name="validation">A MapWindow.Main.ValidationType enumeration specifying acceptable validation to return OK.</param>
 /// <param name="icon">Specifies an icon to appear on this messagebox.</param>
 public InputBox(string text, string caption, ValidationTypes validation, Icon icon)
     : this()
 {
     lblMessageText.Text = text;
     _validation = validation;
     Text = caption;
     ShowIcon = true;
     Icon = icon;
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Creates a new instance of frmInputBox
 /// </summary>
 /// <param name="text">The string message to show.</param>
 /// <param name="caption">The string caption to allow.</param>
 public InputBox(string text, string caption):this()
 {
     lblMessageText.Text = text;
     _validation = ValidationTypes.None;
     Text = caption;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Displays an InputBox form given the specified text string.  The result is returned byref.
 /// A DialogResult is returned to show whether the user cancelled the form without providing input.
 /// </summary>
 /// <param name="owner">The window that owns this modal dialog.</param>
 /// <param name="text">The string text to use as an input prompt.</param>
 /// <param name="caption">The string to use in the title bar of the InputBox.</param>
 /// <param name="validation">A MapWindow.Main.ValidationType enumeration specifying acceptable validation to return OK.</param>
 /// <param name="icon">Specifies an icon to display on this form.</param>
 /// <param name="result">The string result that was typed into the dialog.</param>
 /// <returns>A System.Windows.Forms.DialogResult showing the outcome.</returns>
 public DialogResult LogInputBox(Form owner, string text, string caption, ValidationTypes validation, Icon icon, out string result)
 {
     InputBox frm = new InputBox(owner, text, caption, validation, icon);
     if (frm.ShowDialog() != DialogResult.OK)
     {
         result = "";
     }
     else
     {
         result = frm.Result;
     }
     LogInput(text, frm.DialogResult, result);
     return frm.DialogResult;
 }
Ejemplo n.º 33
0
        public static string CheckRange(ValidationTypes ValidationType, string value, string mask, string minval, string maxval)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }
            DateTime date;

            switch (ValidationType)
            {
            case Validator.ValidationTypes.Integer:
            case Validator.ValidationTypes.SignedInteger:
                long integer;
                if (long.TryParse(value, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowLeadingSign, null, out integer) == false)
                {
                    return(ValidationMessage.ErrInteger);
                }
                // 値の範囲指定がある場合、追加のチェックを行う。
                if (string.IsNullOrWhiteSpace(minval) != true)
                {
                    int ival;
                    if (int.TryParse(minval, out ival) != true)
                    {
                        ival = int.MinValue;
                    }
                    if (integer < ival)
                    {
                        return(string.Format(ValidationMessage.ErrRangeMin, minval));
                    }
                }
                if (string.IsNullOrWhiteSpace(maxval) != true)
                {
                    int ival;
                    if (int.TryParse(maxval, out ival) != true)
                    {
                        ival = int.MaxValue;
                    }
                    if (integer > ival)
                    {
                        return(string.Format(ValidationMessage.ErrRangeMax, maxval));
                    }
                }
                break;

            case Validator.ValidationTypes.Decimal:
            case Validator.ValidationTypes.SignedDecimal:
            case Validator.ValidationTypes.Number:
            case Validator.ValidationTypes.SignedNumber:
                decimal deValue;
                if (decimal.TryParse(value, System.Globalization.NumberStyles.Number, null, out deValue) == false)
                {
                    return(ValidationMessage.ErrDecimal);
                }
                // 値の範囲指定がある場合、追加のチェックを行う。
                if (string.IsNullOrWhiteSpace(minval) != true)
                {
                    var val = Decimal.Parse(minval);
                    if (deValue < val)
                    {
                        return(string.Format(ValidationMessage.ErrRangeMin, minval));
                    }
                }
                if (string.IsNullOrWhiteSpace(maxval) != true)
                {
                    var val = Decimal.Parse(maxval);
                    if (deValue > val)
                    {
                        return(string.Format(ValidationMessage.ErrRangeMax, maxval));
                    }
                }
                break;

            case Validator.ValidationTypes.Date:
                break;

            case Validator.ValidationTypes.DateYYYYMM:
                break;

            case Validator.ValidationTypes.DateMMDD:
                break;

            case Validator.ValidationTypes.DateTime:
            case Validator.ValidationTypes.Time:
                break;

            case Validator.ValidationTypes.ASCII:
                break;

            case Validator.ValidationTypes.Nihongo:
                break;

            case Validator.ValidationTypes.String:
                break;
            }

            return(string.Empty);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// 各タイプに応じて値チェックを行う。
        /// </summary>
        /// <param name="ValidationType">値タイプ</param>
        /// <param name="value">入力値</param>
        /// <returns>
        /// チェック結果
        /// ・true:OK
        /// ・false:NG
        /// </returns>
        public static string Check(ValidationTypes ValidationType, string value, string mask = null, List <string> valuelist = null)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }
            DateTime date;

            switch (ValidationType)
            {
            case Validator.ValidationTypes.Integer:
                long integer;
                if (long.TryParse(value, System.Globalization.NumberStyles.AllowThousands, null, out integer) == false)
                {
                    return(ValidationMessage.ErrInteger);
                }
                break;

            case Validator.ValidationTypes.SignedInteger:
                long integer2;
                if (long.TryParse(value, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowLeadingSign, null, out integer2) == false)
                {
                    return(ValidationMessage.ErrInteger);
                }
                break;

            case Validator.ValidationTypes.Decimal:
            case Validator.ValidationTypes.Number:
                if (!(Regex.IsMatch(value, @"^[-+]?[0-9,\,\.]+$")))
                {
                    return(ValidationMessage.ErrNumber);
                }
                break;

            case Validator.ValidationTypes.SignedDecimal:
            case Validator.ValidationTypes.SignedNumber:
                if (!(Regex.IsMatch(value, @"^[-+]?[0-9,\,\.]+$")))
                {
                    return(ValidationMessage.ErrNumber);
                }
                break;

            case Validator.ValidationTypes.Date:
                if (DateTime.TryParse(value, out date) == false)
                {
                    return(ValidationMessage.ErrDate);
                }
                break;

            case Validator.ValidationTypes.DateYYYYMM:
                string ymd = value + "/1";
                if (DateTime.TryParse(ymd, out date) == false)
                {
                    return(ValidationMessage.ErrDate);
                }
                break;

            case Validator.ValidationTypes.DateMMDD:
                if (DateTime.TryParse(DateTime.Today.ToString("yyyy/") + value, out date) == false)
                {
                    return(ValidationMessage.ErrDate);
                }
                break;

            case Validator.ValidationTypes.DateTime:
            case Validator.ValidationTypes.Time:
                if (DateTime.TryParse(value, out date) == false)
                {
                    return(ValidationMessage.ErrTime);
                }
                break;

            case Validator.ValidationTypes.ASCII:
                if (!(Regex.IsMatch(value, "^[\x20-\x7F]+$")))
                {
                    return(ValidationMessage.ErrASCII);
                }
                break;

            case Validator.ValidationTypes.Nihongo:
                if (!(Regex.IsMatch(value, "^[\u0100-\uFFFF]+$")))
                {
                    return(ValidationMessage.ErrNihongo);
                }
                break;

            case Validator.ValidationTypes.String:
                if (!(Regex.IsMatch(value, "^[\x20-\x7F,\u0100-\uFFFF]+$")))
                {
                    return(ValidationMessage.ErrNihongo);
                }
                break;

            case Validator.ValidationTypes.StringList:
                if (valuelist == null)
                {
                    return(string.Empty);
                }
                foreach (string chkstr in valuelist)
                {
                    if (value == chkstr)
                    {
                        return(string.Empty);
                    }
                }
                return(ValidationMessage.ErrRange);

            case ValidationTypes.CustomAutoComplete:
            case ValidationTypes.EditableAutoComplete:
                if (string.IsNullOrWhiteSpace(mask) != true)
                {
                    if (!(Regex.Match(value, mask)).Success)
                    {
                        return(ValidationMessage.ErrString);
                    }
                }
                break;

            case ValidationTypes.NumberAutoComplete:
                if ((Regex.IsMatch(value, @"^[0-9]$")))
                {
                    return(string.Empty);
                }
                break;

            case ValidationTypes.StringAutoComplete:
                return(string.Empty);
            }

            return(string.Empty);
        }
Ejemplo n.º 35
0
        public static bool InputCheck(ValidationTypes vtype, string text, string custom = null, List <string> valuelist = null)
        {
            bool ret = false;

            switch (vtype)
            {
            case ValidationTypes.None:
                return(true);

            case Validator.ValidationTypes.Integer:
                if ((Regex.IsMatch(text, @"^[0-9]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.SignedInteger:
                if ((Regex.IsMatch(text, @"^[-+]?[0-9]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.Decimal:
            case Validator.ValidationTypes.Number:
                if ((Regex.IsMatch(text, @"^[-+]?[0-9\.\,]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.SignedDecimal:
            case Validator.ValidationTypes.SignedNumber:
                if ((Regex.IsMatch(text, @"^[-+]?[0-9\.\,\-]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.Date:
            case Validator.ValidationTypes.DateYYYYMM:
            case Validator.ValidationTypes.DateMMDD:
                if ((Regex.IsMatch(text, @"^[0-9/]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.Time:
                if ((Regex.IsMatch(text, @"^[0-9:]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.DateTime:
                if ((Regex.IsMatch(text, @"^[0-9/:]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.ASCII:
                if ((Regex.IsMatch(text, "^[\x20-\x7F]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.Nihongo:
                if ((Regex.IsMatch(text, "^[\u0100-\uFFFF]*$")))
                {
                    return(true);
                }
                break;

            case Validator.ValidationTypes.String:
                break;

            case Validator.ValidationTypes.StringList:
                if (valuelist == null)
                {
                    return(true);
                }
                if (valuelist.Contains(text))
                {
                    return(true);
                }
                break;

            case ValidationTypes.CustomAutoComplete:
            case ValidationTypes.EditableAutoComplete:
                if (string.IsNullOrWhiteSpace(custom) == true)
                {
                    return(true);
                }
                if ((Regex.IsMatch(text, custom)))
                {
                    return(true);
                }
                break;

            case ValidationTypes.NumberAutoComplete:
                if ((Regex.IsMatch(text, @"^[0-9]*$")))
                {
                    return(true);
                }
                break;

            case ValidationTypes.StringAutoComplete:
                return(true);
            }

            return(ret);
        }