日期:2014-05-16 浏览次数:20353 次
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>雇员注册验证表单</title>
<script type="text/javascript">
function validate(f) {
var usernumber = f.usernumber.value;
var username = f.username.value;
var userjob = f.userjob.value;
/* var userdate = f.userdate.value;*/
var basicsalary = f.basicsalary.value;
var bonus = f.bonus.value;
if(!/^\d+$/.test(usernumber)){
alert("雇员编号只能是数字");
f.usernumber.focus();
f.usernumber.select();
return false;
}
if(!/^\S+$/.test(username)){
alert("雇员姓名不能为空");
f.username.focus();
f.username.select();
return false;
}
if(!/^\S+$/.test(userjob)){
alert("雇员工作不能为空");
f.userjob.focus;
f.userjob.select();
return false;
}
if(!/^\d+\.{0,1}\d{0,1}$/.test(basicsalary)){
alert("基本工资必须是数字(小数)");
f.basicsalary.focus();
f.basicsalary.select();
return false;
}
if(!/^\d*\.{0,1}\d{0,1}$/.test(bonus)){
alert("奖金必须是数字(小数)");
f.bonus.focus();
f.bonus.select();
return false;
}
alert("注册成功");
return ture;
}
</script>
</head>
<body>
<form action="" method="post" name="myform" onSubmit="return validate(this)">
雇员编号:<input type="text" name="usernumber" maxlength="3" /><br /><br />
雇员姓名:<input type="text" name="username" /><br /><br />
雇员工作:<input type="text" name="userjob" /><br /><br />
雇佣日期:<select name="userdate1"><option value="">请选择</option></select>年<select name="userdate2"><option value="">请选择</option></select>月<select name="userdate3"><option value="">请选择</option></select>日<br /><br />
基本工资:<input type="text" name="basicsalary" min="1" max="5" /><br /><br />
奖金:<input type="text" name="bonus" /><br /><br />
<input type="submit" value="注册" /> <input type="reset" value="重置" />
</form>
</body>
</html>