Possible Duplicate:
Validate numbers in JavaScript – IsNumeric()
I have the following (working) code that searches for the string “type 1” in my Json, but how can I search for a number? I am guessing that I need to change RegExp to Number, but I can’t get it to work, it tells me that v.properties.code in not a function.
$.each(geojson.features, function (i, v) {
if (v.properties.code.search(new RegExp(/type 1/i)) != -1) {
Count++;
}
});
Numbers doesn’t have the search function in their prototypes, so you just need to convert it to a string, this way you ensure it will always be a string, and you won’t get that error, even though you should be doing a proper check on your content
or the other (less typing) way