<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" style="width:200px;height:30px;" id="name">
<script>
//验证用户输入的是否是数字
var reg = new RegExp("^[0-9]*$");
var obj = document.getElementById("name");
obj.onblur = function(){
console.log(reg.test(obj.value));
if(!reg.test(obj.value)){
alert("请输入数字")
}
}
// checkIsNum();
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/studyh5/p/9819677.html
时间: 2024-10-16 09:58:45