Home > Blockchain >  How to change validation message from string length ASP.NET Core
How to change validation message from string length ASP.NET Core

Time:10-02

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.

enter image description here

I have put max and min length attributes on the module and when the input is not valid I want to change this message.

enter image description here

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.

https://docs.fluentvalidation.net/en/latest/aspnet.html

  • Related