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

Contributor

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 

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!

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

@Mohammad Amer I would really appreciate if you can share your approach in this thread. It may be useful for next visitors.

@Mohammad Amer

What was your other approach without injecting java script that you used?
You asked for help from other people then not share your own solution!

@nbercasio @nbercasio @ellan1537 you've all mis-read his response. He didn't say he has found a solution but that he has to find a solution that doesn't involve injecting javascript.

The only OOB solution that I know is in the answer I gave at https://techcommunity.microsoft.com/t5/sharepoint/set-max-character-limit-in-lists-multi-line-column...

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

@Mohammad Amer @nbercasio @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.