Forum Discussion
How to add validation to limit characters in SharePoint Online Multiple line of text column
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 AmerJan 02, 2020Brass Contributor
ellan1537
Thanks for your workaround but actually I have to find another approach without injecting java script code to List forms.- normberkyJun 08, 2022Copper ContributorYou asked for help from other people then not share your own solution!
- RobElliottNov 10, 2022Silver Contributor
normberky normberky 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/m-p/3673369/highlight/true#M66004Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
- b8g3rFeb 28, 2022Copper Contributor
- ellan1537Jan 02, 2020Iron Contributor
Mohammad Amer I would really appreciate if you can share your approach in this thread. It may be useful for next visitors.