Client side custom validation using attributes is not accepting messages which have special characters like apostophe

  • Thread starter Thread starter Nivedita_Tewari
  • Start date Start date
N

Nivedita_Tewari

Guest
Code Back ground

Model validation in ASP.NET Core MVC

I am using this approach in my current code.

Asp dot net core 2.2

Problem:

Now, that i need to show my error messages in Different languages like french i saw my messages are resulting in empty string in the UI.


<div>
<input id="cf-tenantid" class="cf-input-box input-validation-error" type="text" data-val="true" data-val-regex=""

data-val-regex-pattern="^[a-zA-Z0-9-]{36}$" data-val-required="" name="TenantId"

value="" aria-describedby="cf-tenantid-error" aria-invalid="true">
<br>
<span id="tenantIdErrorMsg" class="field-validation-error" data-valmsg-for="TenantId" data-valmsg-replace="true">

<span id="cf-tenantid-error" class=""></span></span>
</div>



at back end

public override void AddValidation(ClientModelValidationContext context)
{
MergeAttribute(context.Attributes, "data-val", "true");
MergeAttribute(context.Attributes, "data-val-regex", @"'Tenant Id not in correct format'");
MergeAttribute(context.Attributes, "data-val-regex-pattern", @"^[a-zA-Z0-9-]{36}$");
MergeAttribute(context.Attributes, "data-val-required", @"pas une chaîne valide");
}



Kindly help i have already faced a lot of issues by applying this approach. As soon as I change the message everything is working. I observed +,' etc. special characters are introducing this situation. But having a message in french is a must for this solution to be acceptable. Is this approach not fully developed by msdn, or is there are missing piece forgotten to be documented.

Continue reading...
 
Back
Top