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 入住酒店文案祝福语简短