JQuery checks the number of input strings in both Chinese and English.

Source: Internet
Author: User

JQuery checks the number of input strings in both Chinese and English.

Method 1:

$ (Document ). ready (function () {var tempStr = "abcdefg we are good kids"; var pattern_char =/[a-zA-Z]/g; var pattern_chin =/[\ u4e00-\ u9fa5]/g; var count_char = tempStr. match (pattern_char ). length; var count_chin = tempStr. match (pattern_chin ). length; alert (count_char + '_' + count_chin); // 7-7 });

Method 2:

<script type ="text/javascript"> $(document).ready(function(){   $("#TextBox1").blur(function(){ var tem = $("#TextBox1").val(); var jc_shu = /[0-9]/g; var jc_yin = /[a-zA-Z]/g; var count_shu =tem.match(jc_shu).length; var count_yin =tem.match(jc_yin).length; $("#ts1").text(count_shu + "___" + count_yin ); });  }); </script>  

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.