Input validation and globalization

Since Html5 inputs use a culture invariant format while falled bak inputs uses a current culture format, the server is informed on the format of each input type either through a cookie or an hidden field, so that the model binder may extract all types properly. For more information on this subject, please refer to the mvcct-enhancer documentation

The various possible formats are properly taken into account, also by all client side validation rules.

Standard client side rules have been enhanced to include format validation for all .Net types and the DynamicRangeAttribute

Format validation on both client side and server side is automatically added to all text inputs decorated with a DatatypeAttribute of type Url or EmailAddress. See it live.

Client validation is added to a View by rendering the _ValidationScriptsPartial partial in the scripts section of that View:

@section scripts{
    @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }

Default error messages

It is possible to provide default custom messages for all types of validation, through resource files. This way the developer may avoid to specify an error message each time it decorates a property with a validation attribute. The main resource file and all related culture specific files must be placed in the root of the web application. Then the type associated to the resource must be declared in the Mvc Controls Toolkit options, when the Mvc Controls toolkit is declared in the Startup.cs configure services section (see installation documentation):

services.AddMvcControlsToolkitControls( m => 
    { m.CustomMessagesResourceType = typeof(ErrorMessages); });

All validation attributes related messages must be put under a key equal to the attribute type name. Thus, for instance, error messages for ill formatted email address must be put under "EmailAddressAttribute". Please don't forget the peculiarities of the DynamicRangeAttribute error message.

Format errors for all .net types, instead, mus be under the following keys: ClientFieldMustBeInteger, ClientFieldMustBePositiveInteger, ClientFieldMustBeNumber (float, decimals, and doubles), ClientFieldMustBeDate, ClientFieldMustBeTime, ClientFieldMustBeDateTime, ClientFieldMustBeWeek, ClientFieldMustBeMonth, ColorAttribute (for colors).

Fork me on GitHub