javascript检查表单格式是否正确
2011-07-04 10:59
435 查看
<! DOCTYPE html PUBLIC "-//W3C//DTD XHYML 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=gb18030" />
<title>添加新设备</title>
<script language="javascript">
function check()
{
while(form.brand.value=="")
{
alert("请填写设备品牌名");
document.form.brand.focus(); //获得鼠标焦点 form为表单的名字
return false;
}
while(form.price.value!="")
{
var a=/^[0-9]{1,10}$/
if (!a.test(form.price.value))
{
alert("价格填写错误");
document.form.price.focus();
return false;
}
}
while(form.imei.value!="")
{var b=/^[0-9]{1,30}$/
if(!b.test(form.imei.value))
{
alert("IMEI填写错误");
document.form.imei.focus();
return false;
}
}
}
</script>
</head>
<body>
添加新设备
<form id="form" name="form" action ="uploadDevice.php" method="post" onSubmit="return check()">
<table border="1" cellpadding ="3" cellspacing="1">
<tr><td>品牌</td><td><input type="text" name="brand" size ="60"></td></tr>
<tr><td>型号</td><td><input type="text" name="type" size ="60"></td></tr>
<tr><td>操作系统</td><td><input type="text" name="os" size ="60"></td></tr>
<tr><td>行/水</td><td><select name="legal"><option value="1"></option><option value="2">行</option><option value="3">水</option></select></td></tr>
<tr><td>IMEI</td><td><input type="text" name="imei" size ="60"></td></tr>
<label>
<tr><td>价格</td><td><input type="text" name="price" size ="60"></td></tr>
</label>
<tr><td colspan="2" align="center"><input type="submit" name="ok" value="提交" onclick="check()"> <input type="reset" name="cancel" value ="重填"></td></tr>
</table>
</form>
</body>
</html>
<html xmlns ="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html"; charset=gb18030" />
<title>添加新设备</title>
<script language="javascript">
function check()
{
while(form.brand.value=="")
{
alert("请填写设备品牌名");
document.form.brand.focus(); //获得鼠标焦点 form为表单的名字
return false;
}
while(form.price.value!="")
{
var a=/^[0-9]{1,10}$/
if (!a.test(form.price.value))
{
alert("价格填写错误");
document.form.price.focus();
return false;
}
}
while(form.imei.value!="")
{var b=/^[0-9]{1,30}$/
if(!b.test(form.imei.value))
{
alert("IMEI填写错误");
document.form.imei.focus();
return false;
}
}
}
</script>
</head>
<body>
添加新设备
<form id="form" name="form" action ="uploadDevice.php" method="post" onSubmit="return check()">
<table border="1" cellpadding ="3" cellspacing="1">
<tr><td>品牌</td><td><input type="text" name="brand" size ="60"></td></tr>
<tr><td>型号</td><td><input type="text" name="type" size ="60"></td></tr>
<tr><td>操作系统</td><td><input type="text" name="os" size ="60"></td></tr>
<tr><td>行/水</td><td><select name="legal"><option value="1"></option><option value="2">行</option><option value="3">水</option></select></td></tr>
<tr><td>IMEI</td><td><input type="text" name="imei" size ="60"></td></tr>
<label>
<tr><td>价格</td><td><input type="text" name="price" size ="60"></td></tr>
</label>
<tr><td colspan="2" align="center"><input type="submit" name="ok" value="提交" onclick="check()"> <input type="reset" name="cancel" value ="重填"></td></tr>
</table>
</form>
</body>
</html>
相关文章推荐
- JavaScript检查是否是正确的日期格式的代码
- 基于jquery实现即时检查格式是否正确的表单
- JavaScript检查是否是正确的日期格式的代码
- 基于jquery实现即时检查格式是否正确的表单
- 注册界面 用javascript检查输入信息格式是否正确 完整版
- 利用JavaScript检查用户注册信息是否正确,在以下情况不满足时报错并阻止提交表单
- JavaScript 判断用户输入的格式是否正确
- JS(JavaScript)判断邮箱格式是否正确
- 用JavaScript的正则表达式验证网址格式是否正确,方法很多,这只是一个实现的方法.
- 用javascript检查yyyy-mm-dd格式的正确源码。
- 检查邮箱是否为正确的格式
- javascript检查表单数据是否改变的方法
- JavaScript 判断用户输入的邮箱及手机格式是否正确
- javascript检查表单数据是否改变
- [JavaScript]JavaScript判断日期格式是否正确
- JavaScript检查手机格式是否错误
- JavaScript检查表单是否为空的函数
- javascript检查表单数据是否改变的方法
- json formatter(一个检查json格式是否正确的小工具)
- JavaScript检查手机格式是否错误