55
rated 0 times
[
56]
[
1]
/ answers: 1 / hits: 19122
/ 9 Years ago, fri, august 7, 2015, 12:00:00
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:
var textBoxValue = $(textbox).val();
function countHowManyWildCards(stringToSearch) {
var regex = new RegExp(/*/g);
var count = stringToSearch.toString().match(regex).length;
return count;
}
if (countHowManyWildCards(textBoxValue) > 1) {
//Other code
}
The code seems to work, but there is an error appearing on:
stringToSearch.toString().match(regex).length;
The error states:
Unable to get property 'length' of undefined or null reference
But I am unclear why the code works, but I still have this error? Can someone fill me in on why this happening?
More From » jquery