求一个正则表达式,只能输入整数0-9,允许保留一位小数

就是验证 打折 的正则表达式

紫衣仙女
浏览 3939回答 3
3回答

桃花长相依

<script>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; function test (str) {&nbsp; &nbsp; &nbsp; &nbsp; return /^[0-9]{1}(\.[0-9])?$/.test(str);&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; console.log(test('1'))&nbsp; &nbsp; // true&nbsp; &nbsp; console.log(test('1.1'))&nbsp; // true&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; console.log(test('1.'))&nbsp; &nbsp;//fasle&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; console.log(test('1.11')) //false</script>

肥皂起泡泡

/^[1-9]\d*\.[1-9]$|0\.[1-9]$|^([^0]\d*)$|^0$/
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript