check if string contains space javascript code example
Example 1: javascript detect space in string
if(str.indexOf(' ') >= 0){
console.log("contains spaces");
}
Example 2: check whitespace in javascript
if (/\s/.test(str)) {
// It has any kind of whitespace
}
Example 3: js find space in string
if(str.indexOf(' ') >= 0){
console.log("contains spaces");
}
Example 4: check if input have word not space only
if (/\s/.test(str)) {
// It has any kind of whitespace
}