开发者

Regular Expression to limit characters to 5000

开发者 https://www.devze.com 2023-02-21 18:56 出处:网络
I need a regular expression to simply limit the number of characters 开发者_如何学JAVAin a textareato 5000.

I need a regular expression to simply limit the number of characters 开发者_如何学JAVAin a textarea to 5000. If there are more secure regular expressions I could use, I am open to suggestions.

Thanks


^.{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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号