Reputation: 191
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.
Upvotes: 0
Views: 868
Reputation: 3750
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.
https://docs.fluentvalidation.net/en/latest/aspnet.html
Upvotes: 1
Reputation: 191
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
Upvotes: 1