How to Check for Whitespace With Javascript
- 1). Create a new JavaScript function. For example, type:
function hasWhitespace(string) { - 2). Define a regular expression that will match whitespace in a string. For example, type:
var ws = /^\s+$/; - 3). Use the "test" method to test for the existence of whitespace and return true or false according to the results. For example, type:
if (ws.test(string))
return true;
else
return false;
}