<script language = 'javascript'> //校验是否为英文 function checkchar() { var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for (i=0; i < document.form.aaa.value.length; i++) { var CheckChar = document.form.aaa.value.charAt(i); CheckChar = CheckChar.toUpperCase(); if (Letters.indexOf(CheckChar) == -1) { alert ("输入类型必须为英文!"); return false; } } }
//校验是否为数字
function checknum(p) { if (p == "") {alert ("输入不能为空!"); return false; } var l = p.length; var count=0; for(var i=0; i<l; i++) { var digit = p.charAt(i); if(digit == "." ) { ++count; if(count>1) {alert ("输入类型必须为数字!"); return false; } } else if(digit < "0" || digit > "9") {alert ("输入类型必须为数字!"); return false; } } return true; }
//校验IP地址格式 function checkip() { var scount=0; var ip = document.form3.ccc.value; var iplength = ip.length; var Letters = "1234567890."; for (i=0; i < document.form3.ccc.value.length; i++) { var CheckChar = document.form3.ccc.value.charAt(i); if (Letters.indexOf(CheckChar) == -1) { alert ("IP地址格式不对!!,只能输入数字和“.”,格式为XXX.XXX.XXX.XXX 例如:192.168.0.1"); document.form3.ccc.value=""; document.form3.ccc.focus(); return false; } }
for (var i = 0;i<iplength;i++) (ip.substr(i,1)==".")?scount++:scount; if(scount!=3) { alert ("IP地址格式不对!,只能输入数字和“.”,格式为XXX.XXX.XXX.XXX 例如:192.168.0.1"); document.form3.ccc.value=""; document.form3.ccc.focus(); return false; }
first = ip.indexOf("."); last = ip.lastIndexOf("."); str1 = ip.substring(0,first); subip = ip.substring(0,last); sublength = subip.length; second = subip.lastIndexOf("."); str2 = subip.substring(first+1,second); str3 = subip.substring(second+1,sublength); str4 = ip.substring(last+1,iplength);