简体   繁体   中英

Regular Expression to limit characters to 5000

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

^.{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´sa character class that says: match whitespace ( \\s ) or non-whitespace ( \\S ) -- ie any possible character
  • Repeat that between zero and 5000 times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM