如何限制用户可以输入 ckeditor 的字符数?
我正在使用 CKeditor,我需要能够对其施加 maxLength 限制。 例如,阻止用户输入超过 100 个字符,不包括 html 字符 由用户应用。
有人能够做到这一点吗?
谢谢,如果您向我指出资源,我将不胜感激。我在这里发现了类似的问题,但它们没有多大帮助。
I'm using the CKeditor and I need to be able 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑即使有人发布了一种方法,这最终是否会可靠。考虑以下内容:
这应该与大多数标签相匹配,但是如果有人做了这样的奇怪事情怎么办:
现在,应该忽略标签的正则表达式错误地识别了该图像的 alt 标签的内容,并将其计入其字符限制。如果某些后端系统要求文本内容仅为 100 个字符,我建议做的是为用户提供最大长度为 100 的单个文本输入,然后寻找另一个控件或库来让他们更改其外观和通过CSS感受。
尝试去掉 HTML 标签然后计算剩余的字符除了让您头疼之外不会做任何事情,在最好的情况下很容易出错,在最坏的情况下会完全出现故障。
I doubt this is going to end up being reliable even if someone posts an approach. Consider the following:
That should match most tags, but what if you get someone who does something screwy like this:
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.