开发者

Regular exp to check minumum 200 characters, including spaces

开发者 https://www.devze.com 2023-04-08 02:36 出处:网络
I need to create a regular expression to check for a minimum of 200 characters, including spaces. It should accept any characters from the keyboard 开发者_如何学运维I am new to javascript. How do I do

I need to create a regular expression to check for a minimum of 200 characters, including spaces. It should accept any characters from the keyboard 开发者_如何学运维I am new to javascript. How do I do it?


A regular expression which matches all characters, with a minimum of 200 is this one:

/[\S\s]{200,}/
  • \S - Any non-whitespace characters
  • \s - Any whitespace character
  • [\S\s] - Any non-whitespace and whitespace character = any characters
  • [\S\s]{200,} - Any character, at least 200 times.


I would have to agree with the person that commented on your answer. A regular expression is not the way to go (at least with the limited information you have provdided). If you go to the mdn entry on strings you will see that every string in JavaScript has a property that you can access called "length" which tells you exactly how many characters/bytes the string is composed of. Like so:

var myNewString = 'foo and bar';
    myNewString.length //returns 11
    'foo and bar'.length //returns 11
0

精彩评论

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