码迷,mamicode.com
首页 > 其他好文 > 详细

正则验证用户输入的是否是数字

时间:2018-10-19 23:50:32      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:type   on()   用户输入   console   log   ext   exp   doctype   check   

<!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>

正则验证用户输入的是否是数字

标签:type   on()   用户输入   console   log   ext   exp   doctype   check   

原文地址:https://www.cnblogs.com/studyh5/p/9819677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!