jQuery Data Type How to - Check if string contains characters and whitespace, not just whitespace








Question

We would like to know how to check if string contains characters and whitespace, not just whitespace.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
myString='this is a test';
if (/\S/.test(myString)) {<!--  w  w  w  .  j  ava  2s .co  m-->
    document.writeln("NOT JUST WHITESPACE");
}
else
    document.writeln("ONLY WHITESPACE");
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: