Total noob here, I'm currently studying regex in javascript. I have a function that is supposed to pick numbers between 0 and 9 from a string. The function works fine as long as the variable it searches has letters or numbers, however when a null value is entered it gives out the following error:
Uncaught: TypeError: Cannot read property 'toString' of null
How can I fix this? Thank you in advance.
Here is the code:
var lause = "s0m3 p30pl3";
function tulostanumerot();
var numerot = /[0-9]/g;
var testi = numerot.test(0-9);
var setti = lause.match(numerot);
if (testi === true) {
console.log(setti.toString());
}
else {
console.log("Ei numeroita!");
};