Jump to content

at least 7 words separated by commas?


jamiet757

Recommended Posts

I am trying to figure out how to tell if what a user enters in a textbox is at least 7 words, separated by commas. It can be 100 words, I don't care, as long as it is at least 7. It will appear like this:

 

word1,word2,word3,word4,word5,word6,word7

 

or

 

word1, word2, word3, word4, word5, word6, word7 (with spaces)

 

Anyone have a statement that I can use?

 

Coincidentally, I need to check to see if there is at least 7 words in a sentence as well, i.e.:

 

The quick brown fox jumped over the.

 

It could be 100 words again, but it needs to be a minimum of 7.

 

Any help is appreciated!

Link to comment
https://forums.phpfreaks.com/topic/199688-at-least-7-words-separated-by-commas/
Share on other sites

The previous code will work, but can be tricked with '      ' or ',,,,,,,,'. A better solution could be created with Regex if needed. Something like this to check for comma separated.

 

'#([^,]+,){7,}#i'

 

...and for the spaces...

 

'#([^ ]+ ){7,}#i'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.