AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

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

51自学网 http://www.wanshiok.com
js,正则匹配,中文,标点符号,js正则匹配中文

本文实例讲述了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>

PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:

JavaScript正则表达式在线测试工具:
http://tools.wanshiok.com/regex/javascript

正则表达式在线生成工具:
http://tools.wanshiok.com/regex/create_reg

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


js,正则匹配,中文,标点符号,js正则匹配中文  
上一篇:分享JavaScript与Java中MD5使用两个例子  下一篇:jquery实现点击其他区域时隐藏下拉div和遮罩层的方法