Install-Package coolvalidator
using CoolValidator;
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
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"
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.
To validate your entity use
In the example above we took in the first error a list of possible errors, The error list is composed of
Then we showed the error in a MessageBox
You can do whatever you want with these error messages, make yourself comfortable
It is available under the MIT license. License