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

  • Question

  • Code Back ground


    I am using this approach in my current code. 

    Asp dot net core 2.2


    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.

    • Moved by CoolDadTx Thursday, May 2, 2019 1:44 PM ASP.NET related
    Thursday, May 2, 2019 7:01 AM

All replies

  • Hi Nivedita_Tewari,

    Thank you for posting here.

    Since this thread is related to asp.net core, you could post in the following forum.


    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 2, 2019 8:12 AM