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

%3CLINGO-SUB%20id%3D%22lingo-sub-1075943%22%20slang%3D%22en-US%22%3EHow%20to%20add%20validation%20to%20limit%20characters%20in%20SharePoint%20Online%20Multiple%20line%20of%20text%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1075943%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20to%20add%20validation%20to%20limit%20number%20of%20characters%20in%20SharePoint%20Online%20Multiple%20line%20of%20text%20column.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20single%20line%20of%20text%20there%20is%20an%20OOB%20option%20%22Column%20Validation%22%26nbsp%3BFormula%20but%20it%20doesn't%20exist%20with%20%22Multiple%20line%20of%20text%22%20column.%3CBR%20%2F%3EIs%20it%20possible%20to%20do%20such%20validation%20using%20SPFX%20extension%20or%20any%20other%20options.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1075943%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESites%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1084560%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20validation%20to%20limit%20characters%20in%20SharePoint%20Online%20Multiple%20line%20of%20text%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1084560%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F187246%22%20target%3D%22_blank%22%3E%40Mohammad%20Amer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EYou%20can%20set%20the%20character%20limit%20by%20making%20use%20of%20maxlength%20attribute%20of%20TextArea%20element%20for%26nbsp%3BMultiple%20lines%20of%20text%20column%20with%20%22%3CSTRONG%3EPlain%20Text%3C%2FSTRONG%3E%22.%20Inject%20the%20below%20script%26nbsp%3B%3CSPAN%20class%3D%22pun%22%3Einto%20NewForm.aspx%20and%20EditForm.aspx%20of%20SharePoint%20List%20and%20replace%26nbsp%3B%22FieldName%22%20with%20your%20field%20name.%3C%2FSPAN%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3E%24(%26nbsp%3Bdocument%26nbsp%3B).ready(function()%26nbsp%3B%7B%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3E%26nbsp%3B%20%26nbsp%3B%20%24(%22textarea%5Bid*%3DFieldName%5D%22).attr('maxlength'%2C'1000')%3B%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%230000FF%22%3E%7D)%3B%3C%2FFONT%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3EFor%20Enhanced%20Rich%20Text%3A%26nbsp%3B%3C%2FSTRONG%3ESharePoint%20renders%20this%20field%20as%20DIV%20with%26nbsp%3B%3CEM%3Econtenteditable%26nbsp%3B%3C%2FEM%3Eattribute%20set.%26nbsp%3B%3CSPAN%3EFor%20this%20DIV%2C%20maxlength%20does%20not%20work.%20So%20need%20to%20control%20the%20keydown%20event%20to%20limit%20the%20characters%20in%20the%20DIV.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3Evar%20max%20%3D%201000%3B%3CBR%20%2F%3E%24(%22DIV%5Bid*%3DFieldName%5D%5Brole%3Dtextbox%5D%22).keydown(function%20(e)%20%7B%20check_charcount(max%2C%20e)%3B%20%7D)%3B%3CBR%20%2F%3Efunction%20check_charcount(max%2C%20e)%20%7B%3CBR%20%2F%3Eif%20(e.which%20!%3D%208%20%26amp%3B%20e.which%20!%3D%2046%20%26amp%3B%20e.which%20!%3D%2037%20%26amp%3B%20e.which%20!%3D%2039%3CBR%20%2F%3E%26amp%3B%20%24(%22DIV%5Bid*%3DFieldName%5D%5Brole%3Dtextbox%5D%22).text().length%20%26gt%3B%20max)%20%7B%3CBR%20%2F%3Ee.preventDefault()%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSPAN%3EHope%20this%20helps!%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1085507%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20validation%20to%20limit%20characters%20in%20SharePoint%20Online%20Multiple%20line%20of%20text%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1085507%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F287320%22%20target%3D%22_blank%22%3E%40ellan1537%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EThanks%20for%20your%20workaround%20but%20actually%20I%20have%20to%20find%20another%20approach%20without%20injecting%20java%20script%20code%20to%20List%20forms.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1086413%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20add%20validation%20to%20limit%20characters%20in%20SharePoint%20Online%20Multiple%20line%20of%20text%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1086413%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F187246%22%20target%3D%22_blank%22%3E%40Mohammad%20Amer%3C%2FA%3E%26nbsp%3BI%20would%20really%20appreciate%20if%20you%20can%20share%20your%20approach%20in%20this%20thread.%20It%20may%20be%20useful%20for%20next%20visitors.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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.

3 Replies
Highlighted

@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!

Highlighted

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

Highlighted

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