jQuery检测输入的字符串包含的中英文的数量
方法一:
$(document).ready(function(){
vartempStr="abcdefg我们都是好孩子";
varpattern_char=/[a-zA-Z]/g;
varpattern_chin=/[\u4e00-\u9fa5]/g;
varcount_char=tempStr.match(pattern_char).length;
varcount_chin=tempStr.match(pattern_chin).length;
alert(count_char+'_'+count_chin);//7-7
});
方法二:
<scripttype="text/javascript">
$(document).ready(function(){
$("#TextBox1").blur(function(){
vartem=$("#TextBox1").val();
varjc_shu=/[0-9]/g;
varjc_yin=/[a-zA-Z]/g;
varcount_shu=tem.match(jc_shu).length;
varcount_yin=tem.match(jc_yin).length;
$("#ts1").text(count_shu+"___"+count_yin);
});
});
</script>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<divid="ts1"></div>
<divid="ts2"></div>
<br/>
<divclass="newStyle1"style="height:506px;width:388px"></div>
</div>
</form>
</body>
以上所述就是本文的全部内容了,希望大家能够喜欢。
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短