当前位置:网站首页>2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)
2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)
2022-06-24 22:38:00 【Little radish】
One 、 Determine the number of digits in a string number

give an example :
console.log('10'.length); // 2
console.log('120'.length); // 3
Two 、 Judge the number of digits of numerical type

Need to go through first
Numeric number +''take Numeric number convert to String number .
give an example :
console.log((10+'').length); // 2
console.log((120+'').length); // 3
3、 ... and 、 Limit text length ( At most n A word , beyond ...)
/* text: Text content n: Limit length */
function limitTextLength(text,n) {
return text.match(/[\u4E00-\[email protected]#$%^&*()_+-=.]/g).length>n?text.substring(0,n)+'…':text
}
limitTextLength(' It will be a great task for us ',6); // ' The great task will fall on …'
limitTextLength('Rabbits like carrots',9); // 'Rabbits l…'
limitTextLength(' Pink &&Rabbits like carrots',9); // ' Pink &&Rabbi…'
【 Add 】 Limit the format of text content according to project requirements , Stay if necessary 、 If not, delete .
\u4E00-\[email protected]#$%^&*()_+-=.Split into four parts from left to right :
\u4E00-\u9FA5(Chinese characters)a-zA-Z(Case letters)0-9(Numbers)[email protected]#$%^&*()_+-=.(Special characters)

边栏推荐
- 网上立案流程
- Principles of Ethernet port mirroring, link aggregation and VLAN Technology
- Huada 04A operating mode / low power consumption mode
- STP spanning tree protocol Foundation
- MySQL + JSON = King fried!!
- Why can some programmers get good offers with average ability?
- try-with-resources 中的一个坑,注意避让
- Selection and comparison of message oriented middleware MQ
- socket done
- Introduction, installation and use of postman tool
猜你喜欢

NIO、BIO、AIO

Creating files, recursively creating directories

ACL (access control list) basic chapter - Super interesting learning network

Servlet details
How to solve the problem that the computer suddenly can't connect to WiFi

JMM 最最最核心的概念:Happens-before 原则

Zero code can apply data visualization to enterprise management

HTTP的缓存控制

The ktp900f mobile download program of the fail safe mobile panel prompts that the download cannot be performed, and the target device is running or not in the transmission mode

Row and column differences in matrix construction of DX HLSL and GL glsl
随机推荐
CA Zhouji - the first lesson in 2022 rust
Embedded development: tips and tricks -- clean jump from boot loader to application code
Problèmes de concurrence dans l'allocation de mémoire en tas
ACL (access control list) basic chapter - Super interesting learning network
Interrupt, interrupted, isinterrupted differences
Idea global search replace shortcut key
2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)
如何比较两个或多个分布:从可视化到统计检验的方法总结
socket(1)
In the era of full programming, should I give up this road?
证件照处理
Redis hop table
FANUC机器人_KAREL编程入门学习(1)
Principles of Ethernet port mirroring, link aggregation and VLAN Technology
CSRF and SSRF for web attacks
Heavyweight! Fada is listed as a "specialized and new" enterprise
Layer 2 and layer 3 forwarding principle based on VLAN
socket done
Cache control of HTTP
Data communication and physical network