Count the number of integers in a string

后端 未结 4 2278
不思量自难忘°
不思量自难忘° 2020-11-29 09:15

how can I count the number of integers in a string using jQuery or javascript?

For example g66ghy7 = 3

4条回答
  •  我在风中等你
    2020-11-29 09:43

    The simplest solution would be to use a regular expression to replace all but the numeric values and pull out the length afterwards. Consider the following:

    var s = 'g66ghy7'; 
    alert(s.replace(/\D/g, '').length); //3
    

提交回复
热议问题