当前位置:网站首页>Chinese verification of JS regular expressions (turn)
Chinese verification of JS regular expressions (turn)
2022-07-04 23:22:00 【Your beauty fascinates me】
Today, do the input box condition verification of form submission , Verify whether Chinese is included ; Online search a circle based on js Regular expression verification is not easy to use , And most of them are from one or two original posts ! What on earth is taking doctrine . According to the search results , This article extracts the essence. , Tell you an easy-to-use Chinese verification method .
Use js Regular expressions match Chinese , Need to know Chinese characters in unicode The interval in the code . Only in this way can we understand the matching principle of expressions .
First use in regular expressions Unicode, You have to use u start , Then there are four bits of character encoding 16 Base representation
Simple Chinese matching method : /[^u0000-u00FF]/ ( Match non single byte characters )
Another wrong method :/[^u00-uFF]/ ( matching Non single byte characters 、 It also includes some width symbols, such as ,.(){}'"! etc. 、 also vwxyz character )
explain : //u0000-u00ff. contain unicode Single byte encoding ( 0-255 code ) Contains basic control characters and Latin letters . Use the negative expression , Roughly judge whether it contains Chinese .
Specific methods of matching Chinese and characters :/[u4E00-u9FA5uF900-uFA2D]/
explain : u4e00-u9fbf : unicode CJK( China, Japan and South Korea ) Unified ideograph .u9fa5 Later u9fbf It's empty
uF900-uFAFF : by unicode CJK Compatible with hieroglyphs .uFA2D Later uFAFF It's empty
For details, please refer to unicode Encoding table :http://www.nengcha.com/code/unicode/class/
javascript The code is as follows :
// Whether it contains Chinese ( It also contains Japanese and Korean )
function isChineseChar(str){
var reg = /[u4E00-u9FA5uF900-uFA2D]/;
return reg.test(str);
}
// Empathy , Whether there is a function with full angle symbol
function isFullwidthChar(str){
var reg = /[uFF00-uFFEF]/;
return reg.test(str);
}
边栏推荐
- 位运算符讲解
- The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
- Why does infographic help your SEO
- cout/cerr/clog的区别
- Phpcms paid reading function Alipay payment
- The caching feature of docker image and dockerfile
- Network namespace
- Redis introduction complete tutorial: detailed explanation of ordered collection
- 法国学者:最优传输理论下对抗攻击可解释性探讨
- SPH中的粒子初始排列问题(两张图解决)
猜你喜欢
MariaDB的Galera集群应用场景--数据库多主多活
Redis getting started complete tutorial: publish and subscribe
Redis: redis transactions
JS card style countdown days
C language to quickly solve the reverse linked list
C语言快速解决反转链表
Redis:Redis的事务
Qualcomm WLAN framework learning (30) -- components supporting dual sta
Intelligence test to see idioms guess ancient poems wechat applet source code
OSEK standard ISO_ 17356 summary introduction
随机推荐
Advantages of Alibaba cloud international CDN
VIM editor knowledge summary
ECS settings SSH key login
为什么信息图会帮助你的SEO
Application of machine learning in housing price prediction
Editplus-- usage -- shortcut key / configuration / background color / font size
Redis:Redis的事务
Docker镜像的缓存特性和Dockerfile
【爬虫】数据提取之JSONpath
QT personal learning summary
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
Redis: redis transactions
The small program vant tab component solves the problem of too much text and incomplete display
【剑指offer】1-5题
位运算符讲解
PICT 生成正交测试用例教程
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
【kotlin】第三天
Mysql database backup and recovery -- mysqldump command
EditPlus--用法--快捷键/配置/背景色/字体大小