Finding spaces in text javascript

Posted on 2008-11-10
Last Modified: 2012-05-05
I have the following function and regular expression to find white spaces, but it returns true no matter what the text is.
var reWhitespace = /(\s)/;

var found = ABN.match(reWhitespace);


Open in new window

Question by:Netlink2
    LVL 16

    Assisted Solution

    Use the test method of RegExp to return true or false.
       var reWhitespace = /(\s)/;
       var ABN = ["Test 1", "Test2"];
       for (var index = 0; index < ABN.length; index++)
          var found = reWhitespace.test(ABN[index]);
          alert("Whitespace " + (found ? "Found" : "Not Found") + ": " + ABN[index]);

    Open in new window

    LVL 15

    Accepted Solution

    ABN = " asdf";
    var reWhitespace = /\s/g;
    var found = ABN.match(reWhitespace);

    Open in new window

    LVL 1

    Author Closing Comment

    Sorry Lolly-Ink I didn't get a chance to try your solution, the pressure is on here :). But I'm sure I'll use your method later in my validation.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    This post first appeared at Oracleinaction  ( Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
    David Varnum recently wrote up his impressions of PRTG, based on a presentation by my colleague Christian at Tech Field Day at VMworld in Barcelona. Thanks David, for your detailed and honest evaluation!
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now