finding spaces

http://stackoverflow.com/questions/14478137/regex-for-validating-fields/14478270#14478270

by powtac

JavaScript

var s = "test test  test ";

// Find multiple spaces
if(s.indexOf("  ") !== -1) {
    alert('Multiple spaces found');
}

// Find leading or trailing space
if (s.indexOf(" ", 0) === 0 || s.indexOf(" ", s.length-1) != -1) {
    alert("Leading or trailing space found");
}