[英]help with making this regExp in js
I need to compare a textarea to make sure: 我需要比较一个文本区域以确保:
Imagine a textarea, I don't want the form to submit if the user have pressed enter (new line) 5 times, and I don't want it to submit with only spaces. 想象一下一个文本区域,如果用户按下Enter键(换行)5次,我不希望表单提交,并且我不希望它仅包含空格。 There must be atleast 3 characters or numbers.
至少应包含3个字符或数字。
Thanks 谢谢
/^\s*(\w[^\w]*){3}.*$/
First, allow leading whitespace. 首先,允许前导空格。 Then match a letter/number followed by 0 or more non-letter/numbers, 3 times.
然后匹配一个字母/数字,后跟0或多个非字母/数字3次。 Then also match any other characters found.
然后还匹配找到的任何其他字符。
Will only match if there are at least 3 letter/number characters; 仅当至少有3个字母/数字字符时才匹配; they can have other characters interspersed between them.
他们之间可以穿插其他字符。
As far as a max character limit goes, it'd be far simpler to just do this with a check on .length
rather than trying to build it into the regex. 就最大字符数限制而言,仅通过检查
.length
而不是尝试将其构建到正则表达式中要容易得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.