admin管理员组文章数量:1287933
I need a regular expression to simply limit the number of characters in a textarea to 5000. If there are more secure regular expressions I could use, I am open to suggestions.
Thanks
I need a regular expression to simply limit the number of characters in a textarea to 5000. If there are more secure regular expressions I could use, I am open to suggestions.
Thanks
Share Improve this question edited Apr 1, 2011 at 16:44 Stephan 43.1k66 gold badges244 silver badges340 bronze badges asked Mar 31, 2011 at 15:53 user671460user671460 211 silver badge2 bronze badges 3- 1 What framework are you using? there may be a built in mechanism for this. – corsiKa Commented Mar 31, 2011 at 15:56
- 2 Just seems like a totally odd thing to do. Why use a Regex for this at all? Surely a simple limit on the string length of the textarea text would be easier to manage and avoid starting the regular expression engine every time someone adds something to the text? – glenatron Commented Mar 31, 2011 at 15:56
- I am using cForms for WordPress. It has built-in support for RegEx, but I'm not sure how to go about adding a string limit length to it. – user671460 Commented Mar 31, 2011 at 16:46
2 Answers
Reset to default 8^.{0,5000}$
should work. Although using a regular expression for this is probably an odd choice.
You will always get the job done with:
^[\s\S]{0,5000}$
- First there´s a character class that says: match whitespace (
\s
) or non-whitespace (\S
) -- i.e any possible character - Repeat that between zero and 5000 times.
本文标签: javascriptRegular Expression to limit characters to 5000Stack Overflow
版权声明:本文标题:javascript - Regular Expression to limit characters to 5000 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741322281a2372273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论