I am trying to convert a phone number on a web page into an integer value but it repeatedly returns NaN, despite being a number. This is part of a chrome extension. My code is as follows:
currNum = String(document.getElementsByClassName("number")[0].innerHTML).trim()
console.log("First: " + currNum)
currNum = currNum.replace("(","").replace(")","").replace("-","").replace(" ","")
console.log("Second: " + currNum)
currNum = parseInt(currNum)
console.log("Third: " + currNum)
The logged output is:
First: (206) 000-0000
Second: 2060000000
Third: NaN
Is there something about this number that can't be cast to an int?
Thanks
currNumvalue. It's probably there in your source HTML content also; in fact that's the only place it could have come from.parseInt()to fail..replace()chain you can add.replace(/[^ -~]/g, "")to get rid of it