How to Check for Whitespace With Javascript

104 22
    • 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;

      }

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.