• Home > Web Front-end > JS Tutorial > body text

    How to implement regular matching of Chinese punctuation marks in js_javascript skills

    WBOY
    Release: 2016-05-16 15:24:03
    Original
    3913 people have browsed it

    The example in this article describes the method of regular js matching Chinese punctuation marks. Share it with everyone for your reference, the details are as follows:

    The screenshot of the running effect is as follows:

    The specific code is as follows:

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>js正则匹配中文标点符号</title>
    <head>
    <body>
    <input type="text" id="textBox" maxlength="1" /> 
    <input type="button" onclick="checkText()" value="提交" />
    <script type="text/javascript">
    function checkText()
    {
      var text = document.getElementById('textBox').value;
      //匹配这些中文标点符号 。 ? ! , 、 ; : “ ” ‘ ' ( ) 《 》 〈 〉 【 】 『 』 「 」 ﹃ ﹄ 〔 〕 … — ~ ﹏ ¥
      var reg = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/;
      if(reg.test(text)){
        alert('是中文标点符号');
      }else{
        alert('不是中文标点符号');
      }
    }
    </script>
    </body>
    </html>
    
    
    Copy after login

    I hope this article will be helpful to everyone in JavaScript programming.

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!