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>
以上所述就是本文的全部内容了,希望大家能够喜欢。
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练