/coolvalidator

Library - TextBox and object validator | C# Windows Form.

Primary LanguageC#MIT LicenseMIT

CoolValidator - Validate TexBox now is easy

How to install

  Install-Package coolvalidator

How to use

Namespace

  using CoolValidator;

Validate TextBox


Default validator

  private void btnSave(object sender, EventArgs e)
  {
      this.ValidateTextBox(ValidateType.IS_EMPTY, PostValidate);
  }

  private void PostValidate()
  {
      MessageBox.Show("Field is Required");
  }
  • ValidateType.IS_EMPTY - Verify if the TextBox is empty
  • PosValidateAction - The method that will run after validation

Custom validator

  private void btnSave(object sender, EventArgs e)
  {
      this.ValidateTextBox(ValidateType.NONE, PostValidate, c =>
                  string.IsNullOrEmpty(c.Text) && c.Tag.Equals("Required"));
  }

  private void PostValidate()
  {
      MessageBox.Show("Field is Required");
  }
  • ValidateType.NONE - Indicate that none validate it will be executed
  • PosValidateAction - The method that will run after validation
  • c => string.IsNullOrEmpty(c.Text) && c.Tag.Equals("Required") - Condition to validate a TextBox, you can put anything.

To validate the example above it's necessary that TextBox be empty and its Tag property be "Required"

required.png

Custom and default validator

  private void btnSave(object sender, EventArgs e)
  {
      this.ValidateTextBox(ValidateType.IS_EMPTY, PostValidate, c =>
                                          c.Tag.Equals("Required"));
  }

  private void PostValidate()
  {
      MessageBox.Show("Field is Required");
  }
  • ValidateType.IS_EMPTY - Varify if the TextBox is empty
  • PosValidateAction - The method that will run after validation
  • c => c.Tag.Equals("Required") - Condition to validate a TextBox, you can put anything.

Validate Entity


Firstly you must create a class with Annotation, example

productClass.png

To validate your entity use

validaTxtInFormPNG.png

In the example above we took in the first error a list of possible errors, The error list is composed of

errorClass.png

Then we showed the error in a MessageBox

warning.png

You can do whatever you want with these error messages, make yourself comfortable


License

It is available under the MIT license. License