我想通过正则表达式验证输入,我正在使用 bootstrap-validate.js https://bootstrap-validate.js.org/ 这是我的代码
它接受 0 到 11 我希望它是 0 到 10 它不接受 12、13 等等
<html>
<form id="rqStudent" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="b_marks" class="form-control" id="b_m" maxlength="2" required/>
</div>
<button type="submit" class="btn btn-primary col-md-12">Request</button>
</form>
<script src="js/bootstrap-validate.js"></script>
<script>
bootstrapValidate('#b_m', 'required|numeric:Please only enter numeric characters!|regex:^[0-10]+$:only 0-10 value acceptable');
</script>
</html>
最佳答案
使用正则表达式:
/^(?:10|[1-9])$/
for (let i=0; i<15; i++)
console.log(i, /^(?:10|[1-9])$/.test(i) );
关于javascript - 使用 bootstrap-validate.js 将输入值设置在 1 到 10 之间的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55530777/