I ended up with the code below, which works really well, as the code at the top seemed to place the number 1 in each one of my text boxes at the start, thanks for all your help!
var fields = ["Text1", "Text2", "Text3", "Text4", "Text5", "Text6", "Text7", "Text8", "Text9", "Text10", "Text11", "Text13", "Text14", "Text15", "Text16", "Text17", "Text18", "Text19", "Text20", "Text21", "Text22", "Text23", "Text24", "Text25", "Text26", "Text27"];
var count = 0;
for (var i=0; i<fields.length; i++) {
var f = this.getField(fields[i]);
if (!/^\s*$/.test(f.valueAsString)) count++;
}
event.value = count;