/// <summary>
        /// This class implements Validation rule to validate required text.
        /// </summary>
        /// <remarks>This validation is rule used by <see cref="T:NeuroSpeech.UIAtoms.Controls.AtomTextBox"/>
        /// control to validate property <see cref="P:System.Windows.Controls.TextElement.Text"/>.
        /// You can use this rule to validate any string property on the control. It returns
        /// <see cref="T:NeuroSpeech.UIAtoms.Validations.AtomValidationError"/> if the string is empty.
        ///
        /// The child classes implement more specific validation by overriding method
        /// <see cref="M:NeuroSpeech.UIAtoms.Validations.AtomStringValidationRule.IsStringValid"/>
        /// to do specific business logic validation.
        /// </remarks>
        /// <param name="view">Control to validate</param>
        /// <param name="property">Dependency Property to validate</param>
        /// <param name="value">Text Value to validate</param>
        /// <returns></returns>
        public override AtomValidationError Validate(View e, BindableProperty property, object value)
        {
            //AtomTrace.WriteLine("AtomTextBox.Validate called...");

            string text       = value as string;
            bool   isRequired = AtomForm.GetIsRequired(e);

            if (isRequired && string.IsNullOrEmpty(text))
            {
                return new AtomValidationError
                       {
                           Property = property,
                           Message  = AtomForm.GetMissingValueMessage(e),
                           Source   = e
                       }
            }
            ;

            int min = GetMinimumLength(e);

            if (min != -1 && min != 0)
            {
                if (text == null || text.Length < min)
                {
                    return(new AtomValidationError
                    {
                        Property = property,
                        Message = string.Format(AtomStringValidationRule.GetMinimumLengthErrorMessage(e), min),
                        Source = e
                    });
                }
            }

            int max = GetMaximumLength(e);

            if (max != -1 && max != 0 && max != int.MaxValue)
            {
                if (text.Length > max)
                {
                    return(new AtomValidationError
                    {
                        Property = property,
                        Message = string.Format(AtomStringValidationRule.GetMaximumLengthErrorMessage(e), min),
                        Source = e
                    });
                }
            }

            return(IsStringValid(value as string, property, e));
        }
Example #2
0
     public override AtomValidationError Validate(View view, BindableProperty property, object value)
     {
         if (AtomForm.GetIsRequired(view))
         {
             if (value == null)
             {
                 return new AtomValidationError
                        {
                            Source   = view,
                            Property = property,
                            Message  = AtomForm.GetMissingValueMessage(view)
                        }
             }
             ;
         }
         return(null);
     }
 }
Example #3
0
     public override AtomValidationError Validate(View view, BindableProperty property, object value)
     {
         if (AtomForm.GetIsRequired(view))
         {
             var dt = DateTime.MinValue;
             if (value != null)
             {
                 dt = Convert.ToDateTime(value);
             }
             if (dt == DateTime.MinValue)
             {
                 return new AtomValidationError
                        {
                            Source   = view,
                            Property = property,
                            Message  = AtomForm.GetMissingValueMessage(view)
                        }
             }
             ;
         }
         return(null);
     }
 }