I need to compare a textarea to make sure:
- It's not ONLY SPACES and not ONLY RETURNS(new lines) and NOT ONLY a combination of these two.
- However, if there are more than 3 characters OR numbers, then it is okay.
- Not more than say 2000 characters.
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. There must be atleast 3 characters or numbers.
Thanks
/^\s*(\w[^\w]*){3}.*$/
First, allow leading whitespace. Then match a letter/number followed by 0 or more non-letter/numbers, 3 times. Then also match any other characters found.
Will only match if there are at least 3 letter/number characters; 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.
精彩评论