An open API service indexing awesome lists of open source software.

https://github.com/mikemajesty/coolvalidator

Library - TextBox and object validator | C# Windows Form.
https://github.com/mikemajesty/coolvalidator

textbox validate validatemanytextbox validatetexbox

Last synced: 10 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# CoolValidator - Validate TexBox now is easy

## How to install
```
Install-Package coolvalidator
```

## How to use
#### Namespace
```
using CoolValidator;
```

## Validate TextBox
___

#### Default validator
```C#
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

```C#
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](https://s17.postimg.org/sxllw9n1r/required.png)](https://postimg.org/image/s82tjwmi3/)

#### Custom and default validator
```C#
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](https://s13.postimg.org/evu7xzbpj/product_Class.png)](https://postimg.org/image/ceigqprsz/)

To validate your entity use

[![validaTxtInFormPNG.png](https://s13.postimg.org/u4p78vbpj/valida_Txt_In_Form_PNG.png)](https://postimg.org/image/t2f0qbsw3/)

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

[![errorClass.png](https://s13.postimg.org/z0ns3g5jb/error_Class.png)](https://postimg.org/image/yb4zr34zn/)

Then we showed the error in a MessageBox

[![warning.png](https://s13.postimg.org/5cpl1muiv/warning.png)](https://postimg.org/image/k8o4985xf/)

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


### License

It is available under the MIT license.
[License](https://opensource.org/licenses/mit-license.php)