Limit the number of character in tinyMCE

后端 未结 16 1166
心在旅途
心在旅途 2020-11-29 07:44

Im using tinyMCe for my project.Everything is working fine but now i want to restrict the number of character that will be insert into tinyMce text

16条回答
  •  生来不讨喜
    2020-11-29 08:00

        // Returns text statistics for the specified editor by id
    function getStats(id) {
        var body = tinymce.get(id).getBody(), text = tinymce.trim(body.innerText || body.textContent);
    
        return {
            chars: text.length,
            words: text.split(/[\w\u2019\'-]+/).length
        };
    } 
    
    
    
    
    
    function submitForm() {
            // Check if the user has entered less than 10 characters
            if (getStats('content').chars < 10) {
                alert("You need to enter 1000 characters or more.");
                return;
            }
    
            // Check if the user has entered less than 1 words
            if (getStats('content').words < 1) {
                alert("You need to enter 1 words or more.");
                return;
            }
    
            // Submit the form
            document.forms[0].submit();
        }
    

    http://www.tinymce.com/wiki.php/How_to_limit_number_of_characters/words

    Hope it helps

提交回复
热议问题