andrebaltieri / Flunt

Validations and Notifications
https://github.com/andrebaltieri/flunt
MIT License
626 stars 162 forks source link

Strings can be null or empty, but if it's not, specific length is needed #22

Closed hugodantas closed 5 years ago

hugodantas commented 6 years ago

Rules added for optional string fields, but if it's not null or empty, some specific length is required (minimum, maximum or exact).

var someStr = "test"; var wrong = new Contract().HasMinLengthIfNotNullOrEmpty(someStr, 10, "string property", "10 characters is the minimum length if string is not null or empty"); var right = new Contract().HasMinLengthIfNotNullOrEmpty(someStr, 3, "string property", "3 characters is the minimum length if string is not null or empty"); var rightAgain = new Contract().HasMinLengthIfNotNullOrEmpty(null, 3, "string property", "3 characters is the minimum length if string is not null or empty");