• Heim  >  Artikel  >  Web-Frontend  >  js实现正则匹配中文标点符号的方法_javascript技巧

    js实现正则匹配中文标点符号的方法_javascript技巧

    WBOY
    WBOYOriginal
    2016-05-16 15:24:033876Durchsuche

    本文实例讲述了js正则匹配中文标点符号的方法。分享给大家供大家参考,具体如下:

    运行效果截图如下:

    具体代码如下:

    <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>
    
    

    希望本文所述对大家JavaScript程序设计有所帮助。

    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn