如何计算文本中的整数个数 [英] how to count no of integers in text

查看:43
本文介绍了如何计算文本中的整数个数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript

How to count no of integers in text anywhere using javascript

推荐答案

使用正则表达式删除所有非数字字符.然后只要检查一下长度即可:
Use a regex to remove all non-digit characters. Then just check the length:
var str="1 23fsd45";
document.write(str.replace(/[^\d]/g,"").length);


这篇关于如何计算文本中的整数个数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆