On Sat, 18 Dec 2004 14:40:24 -0500, Randy Webb <Hi************@aol.com>
wrote:
[snip]
!1 = -1 means it was found in the string.
Precisely. If the index was greater-than or equal to one, the space would
have to occur after the first character.
[snip]
Passes that test but has no space "between" characters.
The best solution would be a regular expression.
/^c+ c+$/ - Two compulsory words separated by a space.
/^c+( c+)?$/ - Two words separated by a space. Second word is
optional.
/^c+( c+)*$/ - Two or more words separated by a space. Only first
word is compulsory.
/^c+( c+)+$/ - Two or more words separated by a space. First two
words are compulsory.
In each case, c should be replaced by a character class or escape, such as
\w or [a-z]. You'd then use:
if(/^\w+( \w+)?$/.test(str)) {
/* String, str, passed */
}
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.