How can i limit the number of characters the user can enter into ckeditor?
I'm using the CKeditor and I need to be a开发者_运维百科ble to impose a maxLength restriction on it. For instance, prevent user from entering more than 100 characters, excluding the html characters applied by the user.
Has anyone been able to do this?
Thanks, I'd appreciate if you point me towards a resource. I found similar questions here but they were not of much help.
I doubt this is going to end up being reliable even if someone posts an approach. Consider the following:
var tags = /<[^>]*?\/?>/;
That should match most tags, but what if you get someone who does something screwy like this:
<img alt=">My Title<" />
Now your regular expression that should be ignoring tags is improperly recognizing the contents of this image's alt tag as counting towards their character limit. If some back end system requires that the text content be only 100 characters what I'd suggest doing is giving the user a single text input with a maxlength of 100, and then look for another control or library that will let them change it's look and feel via CSS.
Attempting to strip out the HTML Tags and then count the remaining characters is unlikely to do anything but give you a headache, will be error prone in the best of cases, and will malfunction entirely in the worst of cases.
精彩评论