標籤:style java color os width io
(非原創)
<html>
<title></title>
<head>
<script language = "javascript">
function cancel(){
document.getElementById("Form").reset();
}
function check(){
//驗證使用者名稱
var username = document.getElementById("username");
if(username.value.length==0){
alert("使用者名稱不可為空!");
username.focus();
return false;
}
if(username.value.length<6){
alert("使用者名稱長度不能低於6位!");
username.value = "";
username.focus();
return false;
}
//驗證密碼,確認密碼
var pass = document.getElementById("password");
var qrpass = document.getElementById("qrpassword");
if(pass.value.length==0){
alert("密碼不可為空!");
pass.focus();
return false;
}
if(pass.value.length<6||pass.value.length>15){
alert("密碼的長度為6-15位!");
pass.value = "";
pass.focus();
return false;
}else if(pass.value!=qrpass.value){
alert("兩次密碼輸入不一致!");
qrpass.value = "";
qrpass.focus();
return false;
}
//驗證社會安全號碼
var idcard = document.getElementById("idcard");
if(idcard.value.length==0){
alert("請輸入你的社會安全號碼碼!");
idcard.focus();
return false;
}
var card = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/
if(!card.test(idcard.value)){
alert("你輸入的社會安全號碼碼不正確,請重新輸入!");
idcard.value="";
idcard.focus();
return false;
}
//驗證性別
var sex = document.getElementsByName("sex");
var boo = true;
for(var i = 0;i<sex.length;i++){
if(sex[i].checked==true){
boo = false;
break;
}
}
if(boo){
alert("請選擇你的性別!");
return false;
}
//驗證出生日期
var data = document.getElementById("birthday");
if(data.value.length==0){
alert("請輸入您的出生日期!");
pass.focus();
return false;
}
//YYYY-MM-DD || YYYY/MM/DD 的日期格式
var a=/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/
if(!a.test(data.value)){
alert("日期格式不正確!\n\n請輸入YYYY-MM-DD或者YYYY/MM/DD的格式!");
return false;
}
//驗證籍貫
var slt=document.getElementById("region");
if(slt.value=="0"){
alert("請選擇你的籍貫!");
return false;
}
//驗證愛好
var flag = true;
var aa = document.getElementsByName("hobby");
for(i = 0;i<aa.length;i++){
if(aa[i].checked==true){
flag = false;
break;
}
}
if(flag){
alert("請選擇你的愛好!");
return false;
}
//驗證郵箱
var objName = document.getElementById("email");
var pattern = /^[a-zA-Z0-9]{1,}@[a-zA-Z0-9]{1,10}[.](com|cn|net)$/;
if(objName.value==0){
alert("請輸入您的郵箱!");
objName.focus();
return false;
}
if (!pattern.test(objName.value)) {
alert("郵箱格式不正確,請重新輸入!");
objName.value="";
objName.focus();
return false;
}
//驗證手機號碼的
var tel = document.getElementById("tel");
var pattern= /^1[358]\d{9}$/
if(tel.value.length==0){
alert("請輸入你的手機號碼!");
tel.focus();
return false;
}
if(!pattern.test(tel.value)) {
alert("你輸入的手機號碼無效,請重新輸入!");
tel.value="";
tel.focus();
return false;
}
//驗證自我介紹
var intro = document.getElementById("intro");
if(intro.value.length==0){
alert("自我介紹不可為空!");
return false;
}else if(intro.value.length<100){
alert("自我介紹字數不能低於100字!");
return false;
}
}
function checknoAll(){
var all = document.getElementsByName("all");
var no = document.getElementsByName("no");
if(no[0].checked==true){
all[0].checked=false;
var all = document.getElementsByName("hobby");
for(i = 0;i<all.length;i++){
if(all[i].checked==true){
all[i].checked=false;
}else if(all[i].checked==false){
all[i].checked=true;
}
}
}
}
function checkAll(){
var all = document.getElementsByName("all");
var no = document.getElementsByName("no");
if(all[0].checked==true){
no[0].checked=false;
var all = document.getElementsByName("hobby");
for(i = 0;i<all.length;i++){
if(!all[i].checked==true){
all[i].checked=true;
}
}
}
}
</script>
</head>
<body>
<form action = "" method = "post" onsubmit = "return check();" id = "Form">
<table border = "1" bordercolor = "green" cellspacing = "1" cellpadding = "1" align = "left" width = "500">
<tr>
<td colspan = "2" align = "center"><font size = "5" color = "green"><b>使用者註冊</b></font></td>
</tr>
<tr>
<td align = "right">使用者名稱:</td><td><input type = "text" id = "username" style = "width:150px;height:20px"/></td>
</tr>
<tr>
<td align = "right">密 碼:</td><td><input type = "password" id = "password" style = "width:150px;height:20px"/></td>
</tr>
<tr>
<td align = "right">確認密碼:</td><td><input type = "password" id = "qrpassword" style = "width:150px;height:20px" onpaste="return false"/> <font color = "red">警告:</font>禁止粘貼</td>
</tr>
<tr>
<td align = "right">社會安全號碼:</td><td><input type = "text" id = "idcard" style = "width:150px;height:20px"/></td>
</tr>
<tr>
<td align = "right">性 別:</td><td>男<input type = "radio" id = "sex" name = "sex" value = "boy"/>女<input type = "radio" name = "sex" id = "sex" value = "girl"/></td>
</tr>
<tr>
<td align = "right">出生日期:</td><td><input type = "text" id = "birthday" style = "width:150px;height:20px"/> <font color = "red">YYYY-MM-DD或者YYYY/MM/DD</font></td>
</tr>
<tr>
<td align = "right">籍 貫:</td><td><select id = "region">
<option value = "0">--請選擇籍貫--</option>
<option value = "1">河南省鄭州市</option>
<option value = "2">河南省信陽市</option>
<option value = "3">北京市海澱區</option>
<option value = "4">遼寧省大連市</option>
<option value = "5">廣東省深圳市</option>
</select>
</td>
</tr>
<tr>
<td align = "right">愛 好:</td><td><input type = "checkbox" id = "hobby" value = "music"/>音樂
<input type = "checkbox" id = "hobby" name = " hobby" value = "basketball"/>籃球
<input type = "checkbox" id = "hobby" name = " hobby" value = "visitor"/>旅遊
<input type = "checkbox" id = "hobby" name = " hobby" value = "sleep"/>睡覺
<font color = "red">*</font>
<input type = "checkbox" id = "all" name = " all" onclick = "checkAll()"/>全選
<input type = "checkbox" id = "no" name = " bo" onclick = "checknoAll()"/>反選</td>
</tr>
<tr>
<td align = "right">郵 箱:</td><td><input type = "text" id = "email" style = "width:150px;height:20px"/></td>
</tr>
<tr>
<td align = "right">手機號碼:</td><td><input type = "text" id = "tel" style = "width:150px;height:20px"/></td>
</tr>
<tr>
<td align = "right">自我介紹:</td><td><textarea id = "intro" style = "width:150px;height:50px"></textarea></td>
</tr>
<tr>
<td colspan = "2" align = "right">
<input type = "submit" value = " 提交註冊資訊 " /> <input type = "reset" onclick = "cancel()" value = " 全部清空 "/>
</td>
</table>
</form>
</body>
</html>