The \ (backslash) in the .match call is not properly escaped. It would be easier to use a regex literal though. Either will work:
var regex = "^\\s+$";
var regex = /^\s+$/;
Also note that + will require at least one space. You may want to use *.