js驗證函式
阿新 • • 發佈:2019-01-27
<script language="JavaScript" type="text/javascript">
function submitUpdateInfo(){
if(document.getElementById("username").value==""){
window.alert("暱稱不能為空");
form1.username.focus();
return false;
}
if(document.getElementById("username").value.length<2||document.getElementById("username").value.length>20){
window.alert("請正確輸入暱稱");
form1.username.focus();
return false;
}
//------------- 身份證要是15位的數字,或18位的數字,17位的數字加上最後一位的字元x.
//身份證不為空
nationCard = document.getElementById("nationid").value;
if(nationCard.length!=15 && nationCard.length!=18){
alert("請正確輸入15或18位的身份證號碼!");
form1.nationid.focus();
form1.nationid.select();
return false;
}
if (nationCard==""||nationCard.length==0){
window.alert("身份證號碼不能空");
form1.nationid.focus();
return false;
}
//身份證的格式
if(nationCard.length==15 ){
if (isNaN(nationCard)){
window.alert("15位身份證的輸入有誤,請正確輸入!");
form1.nationid.focus();
form1.nationid.select();
return false;
}
}
if (nationCard.length==18){
subStr = nationCard.substring(0,17);
lastChar = nationCard.substring(17);
if (isNaN(subStr)){
window.alert("18位身份證輸入有誤,請正確輸入!");
form1.nationid.focus();
form1.nationid.select();
return false;
}else if (isNaN(lastChar)){
if(lastChar!="X" && lastChar!="x"){
window.alert("18位的身份證號碼最後一位有誤!");
form1.nationid.focus();
form1.nationid.select();
return false;
}
}
}
/////---------------------------------身份證檢查結束
if(document.getElementById("email").value==""){
window.alert("電子郵件格式錯誤");
form1.safeemail.focus();
return false;
}
if(document.getElementById("email").value.indexOf('@')==-1||document.getElementById("email").value.indexOf('.')==-1){
window.alert("電子郵件格式錯誤");
form1.safeemail.focus();
return false;
}
if(document.getElementById("city").value==""){
window.alert("城市不為空");
form1.city.focus();
return false;
}
document.form1.submit();
}
function resetUpdateInfo(){
document.form1.reset();
}
function prePic (visualize){
if (visualize=="myVisualize")
document.getElementById("myVisualizeArea").innerHTML="<img src="+document.form1.myVisualize.value+" width=89 height=67 alt=我的形象>";
if (visualize=="personalVisualize")
document.getElementById("personalVisualizeArea").innerHTML="<img src="+document.form1.personalVisualize.value+" width=89 height=67 alt=我的個性形象>";
}
//設定原來性別的選中狀態
document.form1.sex[<%=sexValue%>].checked =true;
</script>
function submitUpdateInfo(){
if(document.getElementById("username").value==""){
window.alert("暱稱不能為空");
form1.username.focus();
return false;
}
if(document.getElementById("username").value.length<2||document.getElementById("username").value.length>20){
window.alert("請正確輸入暱稱");
form1.username.focus();
return false;
}
//------------- 身份證要是15位的數字,或18位的數字,17位的數字加上最後一位的字元x.
//身份證不為空
nationCard = document.getElementById("nationid").value;
if(nationCard.length!=15 && nationCard.length!=18){
alert("請正確輸入15或18位的身份證號碼!");
form1.nationid.focus();
form1.nationid.select();
return false;
}
if (nationCard==""||nationCard.length==0){
window.alert("身份證號碼不能空");
form1.nationid.focus();
return false;
}
//身份證的格式
if(nationCard.length==15 ){
if (isNaN(nationCard)){
window.alert("15位身份證的輸入有誤,請正確輸入!");
form1.nationid.focus();
form1.nationid.select();
return false;
}
}
if (nationCard.length==18){
subStr = nationCard.substring(0,17);
lastChar = nationCard.substring(17);
if (isNaN(subStr)){
window.alert("18位身份證輸入有誤,請正確輸入!");
form1.nationid.focus();
form1.nationid.select();
return false;
}else if (isNaN(lastChar)){
if(lastChar!="X" && lastChar!="x"){
window.alert("18位的身份證號碼最後一位有誤!");
form1.nationid.focus();
form1.nationid.select();
return false;
}
}
}
/////---------------------------------身份證檢查結束
if(document.getElementById("email").value==""){
window.alert("電子郵件格式錯誤");
form1.safeemail.focus();
return false;
}
if(document.getElementById("email").value.indexOf('@')==-1||document.getElementById("email").value.indexOf('.')==-1){
window.alert("電子郵件格式錯誤");
form1.safeemail.focus();
return false;
}
if(document.getElementById("city").value==""){
window.alert("城市不為空");
form1.city.focus();
return false;
}
document.form1.submit();
}
function resetUpdateInfo(){
document.form1.reset();
}
function prePic (visualize){
if (visualize=="myVisualize")
document.getElementById("myVisualizeArea").innerHTML="<img src="+document.form1.myVisualize.value+" width=89 height=67 alt=我的形象>";
if (visualize=="personalVisualize")
document.getElementById("personalVisualizeArea").innerHTML="<img src="+document.form1.personalVisualize.value+" width=89 height=67 alt=我的個性形象>";
}
//設定原來性別的選中狀態
document.form1.sex[<%=sexValue%>].checked =true;
</script>