如何验证文本框输入仅允许整数和正数?
Check out the HTML5 input type="number", you can set min=1 and no max and it will only allow positive whole numbers.
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_number
EDIT: If you just want to use JavaScript, you could try something like this:
if (Number.isInteger(num) && num >= 0) {
//true
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.