谢大神~~
<script>
var str = "a1+b2-3d*4e/5",
nums = str.match(/\d/g).length,
chars = str.match(/[a-z]/gi).length,
others = str.length - numbers - charaters;
alert("数字:" + nums + ",字母:" + chars + ",其它:" + others);
</script>
var str = "a1+b2-3d*4e/5",
nums = str.match(/\d/g).length,
chars = str.match(/[a-z]/gi).length,
others = str.length - numbers - charaters;
alert("数字:" + nums + ",字母:" + chars + ",其它:" + others);
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2014-04-16
var str="dlskjfs3498kldjgfsdafsjf39qt8uldjaf38fksjdfsdkfjS*(F^DS*Fdksljfe892ey";
var s = str.replace(/[0-9]/g,0).replace(/[a-zA-Z]/g,1);
var m=0,n=0,t=0;
for(var i=0,l=s.length;i<l;i++){
var c = s[i];
switch(c){
case '0':
m++;
break;
case '1':
n++;
break;
default:
t++;
break;
}
}
alert("数字有:"+m+",字母有:"+n+",其它有:"+t);追问
var s = str.replace(/[0-9]/g,0).replace(/[a-zA-Z]/g,1);
var m=0,n=0,t=0;
for(var i=0,l=s.length;i<l;i++){
var c = s[i];
switch(c){
case '0':
m++;
break;
case '1':
n++;
break;
default:
t++;
break;
}
}
alert("数字有:"+m+",字母有:"+n+",其它有:"+t);追问
可以在网页上显示一个对话框让用户在对话框里自己输入一段文本吗?
追答最简单的是用prompt:
var name = prompt("请输入用户名");当然,现在基本不用这种弹窗了,难看又不方便,最好自己做一个弹出层
本回答被提问者采纳第2个回答 2014-04-17
用 【正则表达式】 你百度一下