Forum Discussion

Mohammad Amer's avatar
Mohammad Amer
Brass Contributor
Dec 20, 2019

How to add validation to limit characters in SharePoint Online Multiple line of text column

How to add validation to limit number of characters in SharePoint Online Multiple line of text column.

 

For single line of text there is an OOB option "Column Validation" Formula but it doesn't exist with "Multiple line of text" column.
Is it possible to do such validation using SPFX extension or any other options.

7 Replies

  • Mohammad Amer normberky b8g3r ellan1537 

     

    If you are using modern experience SharePoint list forms, you can also customize the list forms using Power Apps and set MaxLength property of text input control related to your column.

     

    MaxLength – The number of characters that the user can type into a text-input control.

     

    DocumentationText Input in Power Apps 

     

    Note: This limit will not be enforced if user tries to edit column value using Grid view (quick edit) or programmatically.


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

  • ellan1537's avatar
    ellan1537
    Iron Contributor

    Mohammad Amer 

    You can set the character limit by making use of maxlength attribute of TextArea element for Multiple lines of text column with "Plain Text". Inject the below script into NewForm.aspx and EditForm.aspx of SharePoint List and replace "FieldName" with your field name.

    $( document ).ready(function() {
        $("textarea[id*=FieldName]").attr('maxlength','1000');
    });

    For Enhanced Rich Text: SharePoint renders this field as DIV with contenteditable attribute set. For this DIV, maxlength does not work. So need to control the keydown event to limit the characters in the DIV.

     

    var max = 1000;
    $("DIV[id*=FieldName][role=textbox]").keydown(function (e) { check_charcount(max, e); });
    function check_charcount(max, e) {
    if (e.which != 8 & e.which != 46 & e.which != 37 & e.which != 39
    & $("DIV[id*=FieldName][role=textbox]").text().length > max) {
    e.preventDefault();
    }
    }

     

    Hope this helps!

    • Mohammad Amer's avatar
      Mohammad Amer
      Brass Contributor

      ellan1537 
      Thanks for your workaround but actually I have to find another approach without injecting java script code to List forms. 

      • normberky's avatar
        normberky
        Copper Contributor
        You asked for help from other people then not share your own solution!

Resources