My question is: How I can count only numbers from a string, for example if I have: (55)-555-34 to get output 7, I mean to exclude the dashes and brackets for example. Cheers!
isDigit(s. charAt(i)) will count the number of digits in the given string. 'Character. isDigit' will count the number of each digit in the string.
To count the number of digits in a string, use the replace() method to replace all non digit characters with an empty string and access the length property on the result. The replace method returns a new string with the matches replaced.
Answer: Use the jQuery . length property The jQuery . length property can be used to get or find out the number of characters in a string. You can also use this property to calculate the number of elements in a jQuery object.
You could use .match() with /\d/g
Regular Expression:
"(55)-555-34".match(/\d/g).length
//result=>7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With