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

边栏推荐
- img2pdf
- Can AI chat robots replace manual customer service?
- 重磅!法大大上榜“专精特新”企业
- Structure du disque
- 1. fully explain the basic principles of IPSec
- Servlet详解
- Chapter 10 project communication management
- In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience
- Problèmes de concurrence dans l'allocation de mémoire en tas
- Zero code can apply data visualization to enterprise management
猜你喜欢

Common voting governance in Dao

2022-06-10 工作记录--JS-获取到某一日期N天后的日期

The usage difference between isempty and isblank is so different that so many people can't answer it

Row and column differences in matrix construction of DX HLSL and GL glsl

NIO、BIO、AIO
Relationnet++: a representation of fusion of multiple detection targets based on transformer | neurips 2020

Redis hop table

Power system | IEEE paper submission process

Kubevela v1.2 release: the graphical operation console velaux you want is finally here

Technology Review: what is the evolution route of container technology? What imagination space is there in the future?
随机推荐
Ideal L9, new trend of intelligent cockpit
How to grab the mobile phone bag for analysis? Fiddler artifact may help you!
Cache control of HTTP
NiO, bio, AIO
L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
Why can some programmers get good offers with average ability?
Can AI chat robots replace manual customer service?
Envoy obtain the real IP address of the client
leetcode:45. Jumping game II [classic greed]
A girl has been making hardware for ten years. 。。
软件设计的七大原则
Raspberry pie preliminary use
面试害怕被问MySQL相关问题 ?这份三万字精华总结 + 面试100 问,吊打面试官完全够了
envoy获取客户端真实IP
CSRF and SSRF for web attacks
Row and column differences in matrix construction of DX HLSL and GL glsl
Information update on automatic control principle
ThreadLocal memory leak
Seven principles of software design
Main steps of system test