-
Notifications
You must be signed in to change notification settings - Fork 1
2.5. String maximum and minimum Length validations
hugoj0s3 edited this page Apr 23, 2018
·
4 revisions
Adding StringMinimumLengthValidation and StringMaximumLengthValidation. In this example below the first name must have at least 3 characters and can not have more than 100 characters.
const string minumumFormatMessage = "{0} must have at least {1} characters";
// {0} will be replaced by nameof(Person.FirstName)
// {1} will be replaced by minumum lenght passed
const string maximumFormatMessage = "{0} must not have more than {1} characters";
// {0} will be replaced by nameof(Person.FirstName)
// {1} will be replaced by maximum lenght passed
private ICompositeValidation<Person> validations = new CompositeValidation<Person>()
.MinimumLength(nameof(Person.FirstName), p => p.FirstName, 3, minumumFormatMessage)
.MaximumLength(nameof(Person.FirstName), p => p.FirstName, 100, maximumFormatMessage);
// Minimum Length is 3 and Maximum Length is 100
- 1. Getting started
-
2. Compositing validations
- 2.1. Null and NotNull validations
- 2.2. Must and MustNot validations
- 2.3. Regular expression validations
- 2.4. Not empty string validations
- 2.5. String maximum and minimum Length validations
- 2.6. Email validations
- 2.7. Not empty collections
- 2.8. Minimum and Maximum size collections
- 2.9. Adding a custom validation
- 3. Updating failure list
- 4. Creating custom validations
- 5. Summary Message