当前位置:网站首页>正则校验匹配[0-100]、[0-1000]之间的正整数或小数点位数限制
正则校验匹配[0-100]、[0-1000]之间的正整数或小数点位数限制
2022-06-11 20:54:00 【赫兹/Herzz】
匹配正整数
[0-100]不含0和100
const reg = /^([1-9][0-9]{0,1}|99)$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
[0-100]含0和100
const reg = /^([0-9][0-9]{0,1}|100)$/ //注意此处细节
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
[0-1000]不含0和1000
const reg = /^([1-9][0-9]{0,2}|999)$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
[0-1000]含0和1000
const reg = /^([0-9][0-9]{0,2}|1000)$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
匹配正数+小数点限制
[0-1000]不含0和1000,保留小数点后一位
const reg = /^([1-9]\d{0,2}|999.9)(\.\d{1})?$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
[0-1000]含0和1000,保留小数点后1位
const reg = /^([0-9]\d{0,2}|1000)(\.\d{1})?$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
[0-10000]不含0和10000,保留小数点后3位
const reg = /^([1-9][0-9]{0,3}(\.\d{1,3})?|9999.999)$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
[0-10000]含0和10000,保留小数点后3位
const reg = /^([0-9][0-9]{0,3}(\.\d{1,3})?|10000)$/
if (reg.test(value) === false) {
console.log(`校验通过---`)
}
注:亲测有效,但含0的情况下01、02、03…会通过校验,有快捷方法的可提出来。
边栏推荐
- 【计算机推免】哈尔滨工业大学物联网与泛在智能研究中心面向全国高校推免生招收2023级研究生(硕、博、直博生)
- 13 r basic exercises
- File upload vulnerability - simple exploitation 2 (Mozhe college shooting range)
- Using the flask framework to write the bezel
- MySQL installation free configuration tutorial under Windows mysql-5.6.51-winx64 Zip version
- UDP、TCP
- [unity plug-in] shader keyword analysis tool shadercontrol
- The scale of the global machine vision market continues to rise. Poe image acquisition card provides a high-speed transmission channel for industrial cameras
- 27. this指向问题
- 成长的12条黄金法则
猜你喜欢

周刊02|不瞒你说,我其实是MIT的学生

新品发布:LR-LINK联瑞推出首款25G OCP 3.0 网卡

第一部分 物理层

【数据可视化】Apache Superset 1.2.0教程 (二)——快速入门(可视化王者英雄数据)
Recompile kubeadm to solve the problem of certificate expiration in one year

新品发布:国产单电口千兆网卡正式量产!

Frequency domain filter

sql优化之DATE_FORMAT()函数

Chinese text classification based on CNN

moderlarts第一次培訓
随机推荐
Recompile kubeadm to solve the problem of certificate expiration in one year
7905 and TL431 negative voltage regulator circuit - regulator and floating circuit relative to the positive pole of the power supply
What is the meaning of holding shares of financial products?
moderlarts第一次培訓
The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%
Redis fourth session - redis high performance principle (multiplexing) and high availability analysis (backup, master-slave)
全球机器视觉市场规模持续上涨,PoE图像采集卡为工业相机提供高速传输通道
moderlarts第一次培训
Solution to the problem of PHP strtotime obtaining natural monthly error
Date of SQL optimization_ Format() function
27. this指向问题
Weekly 02 | pour être honnête, je suis un étudiant du MIT
【数据可视化】Apache Superset 1.2.0教程 (三)—— 图表功能详解
12 date and time in R
Teach you how to grab ZigBee packets through cc2531 and parse encrypted ZigBee packets
Wechat applet Bluetooth development
2022-2028 global and Chinese thermopile detector Market Status and future development trend
Js 监听滚动触底加载更多_浏览器滚动触底加载更多
Final examination of Dialectics of nature 1
新品发布:国产单电口千兆网卡正式量产!