当前位置:网站首页>Regular check matches positive integer or decimal limit between [0-100] and [0-1000]

Regular check matches positive integer or decimal limit between [0-100] and [0-1000]

2022-06-11 21:05:00 Hertz /herzz

Matching positive integer

[0-100] Not included 0 and 100

const reg = /^([1-9][0-9]{0,1}|99)$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

[0-100] contain 0 and 100

const reg = /^([0-9][0-9]{0,1}|100)$/ // Pay attention to the details here 
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

[0-1000] Not included 0 and 1000

const reg = /^([1-9][0-9]{0,2}|999)$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

[0-1000] contain 0 and 1000

const reg = /^([0-9][0-9]{0,2}|1000)$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

Match a positive number + Decimal limit

[0-1000] Not included 0 and 1000, Keep one decimal place

const reg = /^([1-9]\d{0,2}|999.9)(\.\d{1})?$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

[0-1000] contain 0 and 1000, After decimal point 1 position

const reg = /^([0-9]\d{0,2}|1000)(\.\d{1})?$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

[0-10000] Not included 0 and 10000, After decimal point 3 position

const reg = /^([1-9][0-9]{0,3}(\.\d{1,3})?|9999.999)$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

[0-10000] contain 0 and 10000, After decimal point 3 position

const reg = /^([0-9][0-9]{0,3}(\.\d{1,3})?|10000)$/
if (reg.test(value) === false) {
    
  console.log(` Check by ---`)
}

notes : Close test effectively , But including 0 Under the circumstances 01、02、03… Will pass the verification , There are quick ways to come up with .

原网站

版权声明
本文为[Hertz /herzz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112053552902.html