My question is: how can I only count numbers from a string, for example, if I have: (55) -555-34 to get output 7, I mean, for example, exclude dashes and brackets. Hooray!
You can use . match () with /\d/gRegular expression:
/\d/g
"(55)-555-34".match(/\d/g).length //result=>7
Remove all non numbers with replaceand get the line length of the result:
replace
str.replace(/\D/g,"").length
This has the advantage over the application matchthat you do not need to check the results null(if there is no match found).
match
null