怎么判断只能舒服四个数字 js 怎么判读输入的 必须 而且只能是四个数字 不懂正则 请教大家 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style>*{margin:0; padding:0;}</style></head><body> <input type="text" id="t" maxlength="4" /> <input type="button" id="btn" value="click me" /> <script> document.getElementById('btn').onclick = function(){ var value = document.getElementById('t').value; if(!isNaN(+value) && value.length == 4){ alert('是数字') }else{ alert('不是数字或者少于4位') } }; </script></body></html> <!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/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript">window.onload = function() { document.getElementsByTagName('form')[0].onsubmit = function() { var num = document.getElementById('num').value; if (!/^[0-9]{4}$/.test(num)) { alert('必须输入4位数字!'); return false; } if (!/^[1-9]{1}[0-9]{3}$/.test(num)) { alert('必须输入4位正整数!'); return false; } return true; }}</script></head><body><form> <input type="text" id="num" name="num" /> <input type="submit" /></form></body></html> 前些天看到有一篇专门讲javascript function的文章,现在找不到了,求助 菜鸟,如何让输入框根据下拉框调整其内容 火狐浏览器javascript总是多弹一次窗口是何原因?请教高手 请教有关“EMBED”为什么只能播放mid 不能播mp3 或war的文件呢? 与服务器端实时通信问题。 综合整理之后的PowerDate .方便处理常日公历日期操作. 遍历json文件并对数组赋值 问一个根据屏幕分辨率改变层定位问题 ASIC与字符的转换 JS过程中写入ASP语言的问题 iframe页面,如何先执行父页面的方法再执行iframe页面的方法 JS获取时间问题
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{margin:0; padding:0;}
</style>
</head>
<body>
<input type="text" id="t" maxlength="4" />
<input type="button" id="btn" value="click me" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('t').value;
if(!isNaN(+value) && value.length == 4){
alert('是数字')
}else{
alert('不是数字或者少于4位')
}
};
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function() {
document.getElementsByTagName('form')[0].onsubmit = function() {
var num = document.getElementById('num').value;
if (!/^[0-9]{4}$/.test(num)) {
alert('必须输入4位数字!');
return false;
}
if (!/^[1-9]{1}[0-9]{3}$/.test(num)) {
alert('必须输入4位正整数!');
return false;
}
return true;
}
}
</script>
</head><body>
<form>
<input type="text" id="num" name="num" />
<input type="submit" />
</form>
</body>
</html>