title: Unable to get property 'length' of undefined or null reference
body: <p>I have the following code - All it does it grabs the value in a text box, performs regex on the string and then counts how many asterisks are in the string value:</p>
  
  <pre><code>var textBoxValue = $(textbox).val();
  
  function countHowManyWildCards(stringToSearch) {
  
      var regex = new RegExp(/\*/g);
      var count = stringToSearch.toString().match(regex).length;
      return count;
  
  }
  
  if (countHowManyWildCards(textBoxValue) &gt; 1) {
  
  //Other code
  }
  </code></pre>
  
  <p>The code seems to work, but there is an error appearing on:</p>
  
  <pre><code>stringToSearch.toString().match(regex).length;
  </code></pre>
  
  <p>The error states:</p>
  
  <blockquote>
    <p>Unable to get property 'length' of undefined or null reference</p>
  </blockquote>
  
  <p>But I am unclear why the code works, but I still have this error? Can someone fill me in on why this happening?</p>