var input=document.getElementById("input")
input.onblur=function(){
if(parseFloat(input.value) > 1){
alert("输入的值不允许大于1")
input.value=""
}
}
</script>
parseFloat可以判断小数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function go(){
var input = document.getElementById("input")
var value = input.value
if(value <1){
alert("你输入的值"+ value +"小于1")
}else{
alert("正好")
}
}
</script>
</head>
<body>
<input id="input" type="text" />
<input type="button" value="aaaa" onclick="go()"/>
</body>
</html>
完整的实现,其实很简单!!!!
使用正则/^[01]{7}$/就可以,例如:<input type=text onchange="if (! this.value.match(/^[01]{7}$/)) alert('格式错误')">