当前位置:网站首页>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)

边栏推荐
- 重磅!法大大上榜“专精特新”企业
- 虚拟人的产业发展现状
- Docker installs MySQL 8.0. Detailed steps
- Online filing process
- Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware
- Cross border e-commerce, early entry and early benefit
- [Software Engineering] key points at the end of the period
- Servlet详解
- 磁盘的结构
- Development of live broadcast software app, and automatic left-right sliding rotation chart advertising
猜你喜欢

Future development of education industry of e-commerce Express

NIO多路复用之Selector的使用

Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware

Cross border e-commerce, early entry and early benefit

socket(1)

一个女孩子居然做了十年硬件。。。

Ansible basic configuration

NiO zero copy

Ideal L9, new trend of intelligent cockpit

Online filing process
随机推荐
The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
[personal experiment report]
为什么有的程序员能力一般却能拿到好offer?
Future development of education industry of e-commerce Express
Main steps of system test
Envoy obtain the real IP address of the client
What aspects should we start with in the feasibility analysis of dry goods?
证件照处理
YGG 近期游戏合作伙伴一览
Data communication foundation - Ethernet port mirroring and link aggregation
Data communication and physical network
Unable to use the bean introduced into the jar package
seven
Online filing process
ThreadLocal内存泄漏问题
HTTP的缓存控制
NIO、BIO、AIO
AQS source code analysis
Virtual private network foundation
Common voting governance in Dao