当前位置:网站首页>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);
}
边栏推荐
- Mysql database backup and recovery -- mysqldump command
- D3.js+Three. JS data visualization 3D Earth JS special effect
- One of the commonly used technical indicators, reading boll Bollinger line indicators
- Notepad++ -- editing skills
- The difference between cout/cerr/clog
- The small program vant tab component solves the problem of too much text and incomplete display
- Redis: redis transactions
- The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
- 认识ThreadPoolExecutor
- Compare two vis in LabVIEW
猜你喜欢
Redis: redis message publishing and subscription (understand)
Intelligence test to see idioms guess ancient poems wechat applet source code
Jar批量管理小工具
uniapp 除了数字,其他输入无效
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
CTF competition problem solution STM32 reverse introduction
CTF竞赛题解之stm32逆向入门
【kotlin】第三天
One of the commonly used technical indicators, reading boll Bollinger line indicators
cout/cerr/clog的区别
随机推荐
CTF competition problem solution STM32 reverse introduction
Advantages of Alibaba cloud international CDN
认识ThreadPoolExecutor
Tweenmax emoticon button JS special effect
Redis getting started complete tutorial: Geo
【爬虫】数据提取之JSONpath
cout/cerr/clog的区别
Financial markets, asset management and investment funds
D3.js+Three. JS data visualization 3D Earth JS special effect
Phpcms paid reading function Alipay payment
MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
[crawler] jsonpath for data extraction
LabVIEW中比较两个VI
HMS core machine learning service
一次edu证书站的挖掘
debug和release的区别
解决无法通过ssh服务远程连接虚拟机
EditPlus--用法--快捷键/配置/背景色/字体大小
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
Qt个人学习总结