Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to count no of integers in text anywhere using javascript
Posted
Updated 30-Mar-12 22:23pm
v2
Comments
OriginalGriff 31-Mar-12 3:59am    
Depends.
How are you defining that an integer ends? is "1 23" two ints? three? one? or none?
Use the "Improve question" widget to edit your question and provide better information.
mayur csharp G 31-Mar-12 4:01am    
its 3

1 solution

Use a regex to remove all non-digit characters. Then just check the length:
C#
var str="1 23fsd45";
document.write(str.replace(/[^\d]/g,"").length);
 
Share this answer
 
Comments
mayur csharp G 31-Mar-12 6:13am    
Thanks

can you please give to count only small letters
OriginalGriff 31-Mar-12 7:03am    
Change "\d" to "a-z"
mayur csharp G 31-Mar-12 7:13am    
thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900