codice:
matches = mystring.trim().match(/\s/g);
alert( matches.length );
Il metodo trim è supportato nativamente solo nei browser più recenti(almeno per IE), su internet cmq trovi svariate riproduzioni del metodo da utilizzare nel caso non sia supportato.