I want to validate input in a form field that takes string input. ASP.Net Core already checks if it is empty or not because it is required.
I have put max and min length attributes on the module and when the input is not valid I want to change this message.
CodePudding user response:
The solution is really simple. All I had to do was add this attribute to the model property
[StringLength(8, ErrorMessage = "{0} length must be between {2} and {1}.", MinimumLength = 6)]
Where the first parameter is the maximum length and the last parameter is the minimum length
More information about this model validation here
CodePudding user response:
For complex validation requirements, you can check out FluentValiation. It is a great tool to help make your validation easy to create and easy to maintain.