Esempio n. 1
0
        internal void Validate()
        {
            var format = TextBoxValidationExtensions.GetFormat(_textBox);

            var expectNonEmpty = (format & ValidTextBoxFormats.NonEmpty) != 0;
            var isEmpty        = string.IsNullOrWhiteSpace(_textBox.Text);

            if (expectNonEmpty && isEmpty)
            {
                MarkInvalid();
                return;
            }

            var expectNumber = (format & ValidTextBoxFormats.Numeric) != 0;

            if (expectNumber &&
                !isEmpty &&
                !IsNumeric())
            {
                MarkInvalid();
                return;
            }

            MarkValid();
        }
Esempio n. 2
0
        internal void Validate()
        {
            var format = TextBoxValidationExtensions.GetFormat(textBox);

            var expectNonEmpty   = (format & ValidTextBoxFormats.NonEmpty) != 0;
            var expectStartsWith = (format & ValidTextBoxFormats.StartsWith) != 0;
            var isEmpty          = string.IsNullOrWhiteSpace(textBox.Text);

            if (expectNonEmpty && isEmpty)
            {
                MarkInvalid();
                return;
            }

            var startsWith = textBox.Text.StartsWith(TextBoxValidationExtensions.GetStartsWith(textBox), StringComparison.CurrentCultureIgnoreCase);

            if (expectStartsWith && !startsWith && !isEmpty)
            {
                MarkInvalid();
                return;
            }

            var expectNumber = (format & ValidTextBoxFormats.Numeric) != 0;

            if (expectNumber &&
                !isEmpty &&
                !IsNumeric())
            {
                MarkInvalid();
                return;
            }

            var expectDateTime = (format & ValidTextBoxFormats.DateTime) != 0;

            if (expectDateTime &&
                !isEmpty &&
                !IsDateTime())
            {
                MarkInvalid();
                return;
            }

            MarkValid();
        }