博客
关于我
(转)js正则表达式之中文验证
阅读量:136 次
发布时间:2019-02-26

本文共 703 字,大约阅读时间需要 2 分钟。

http://houfeng0923.iteye.com/blog/1035321
首先在正则表达式中使用 Unicode,必须使用\u开头,接着是字符编码的四位16进制表现形式
简单匹配中文方法: /[^\u0000-\u00FF]/ (匹配非单字节字符 )
另错误方法:/[^\u00-\uFF]/ (匹配 非单字节字符、还包括一些全半角符号如,.(){}'"!等、还有vwxyz字符)
说明: //u0000-u00ff.包含unicode单字节编码( 0-255编码)包含基本控制字符和拉丁文字母。 采用该否定表达式,粗略判断是否含有中文。
具体的匹配中文及字符方法:/[\u4E00-\u9FA5\uF900-\uFA2D]/
说明: u4e00-u9fbf :  unicode CJK(中日韩)统一表意字符。u9fa5后至u9fbf为空
uF900-uFAFF :  为unicode  CJK 兼容象形文字  。uFA2D后至uFAFF为空
具体可参考unicode编码表:http://www.nengcha.com/code/unicode/class/
Js代码 
//是否含有中文(也包含日文和韩文) 
function isChineseChar(str){    
   var reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/; 
   return reg.test(str); 
//同理,是否含有全角符号的函数 
function isFullwidthChar(str){ 
   var reg = /[\uFF00-\uFFEF]/; 
   return reg.test(str); 

转载地址:http://vrsf.baihongyu.com/

你可能感兴趣的文章
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>