Library with common value validators to be used in UI application (e.g. ASP.Net Core, Xamarin, UWP, WPF). The library is based on the ideas from the following book:
Service | Last | Develop | Master |
---|---|---|---|
AppVeyor last | |||
SonarCube coverage | |||
SonarCube technical debt | |||
SonarCube Quality Gate | |||
Nuget |
IValidationRule<T>
: Generic interface for the rulesIValidatable
: Interface to handle validationIValidatableValue<T>
: Generic interface for a validatable valueIValidatableValue
: Non geniric interface for validatable value (mostly implemented explizit)
ContainsValidationRule
- Check, if the value is in the given collection (with possibility to inverse the result)EmailValidationrule
- Check, if the value is a valid email addressEqualValuesValidationRule<T>
- Compare two values for equalityNullValidationRule
- Check, if the value isnull
PhoneNumberValidationRule
- Check, if the value is valid phone number (with allowed separators-
,()
,.
)RangeValidationRule<T>
/PrimitiveRangeValidationRule
- Compare the value to a given min and max valuesRegexValidationRule
- Check, if the value match the given regular expressionRequiredValidationRule
- Check, if the string value is set (with a flag, for white spaces treaded as valid values)StringLengthValidationRule
- Check the max or min length of a stringGreaterThanValidationRule
- Check, if the value is greater (or equal) to a given valueSmallerThanValidationRule
- Check, if the value is smaller (or equal) to a given valueRevalidateOtherValueValidationRule
- Trigger the validation of another validatable value
Initialize your validatable values in your view model.
MyValidatableValue = new ValidatableValue<string>
{
ValidationRules = new IValidationRule<string>[]
{
new ContainsValidationRule<string>(
errorMessage: "Value not allowed",
checkCollection: new[] {"test", "example", "fake"},
nullOrEmptyIsValid: true),
new StringLengthValidationRule(
errorMessage: "The value should have at least 2 characters
length: 2,
checkMaxLength: false),
new StringLengthValidationRule(
errorMessage: "The value should have at maximum 16 charachters",
length: 16),
new RequiredValidationRule(errorMessage: "Value is required")
}
};
Bind the value in your XAML code.
...
<Label Text="My value:" />
<Entry Text="{Binding MyValidatableValue.Value}"
BackgroundColor="{Binding MyValidatableValue.IsValid, Converter={StaticResource ValidationColorConverter}}"/>
<Label Text="{Binding MyValidatableValue.FirstError}"
Style="{StaticResource ErrorMessage}" />
...