怎么判断IP地址是否正确
如题!
------解决方案-------------------- <html>
<head>
<title> Javascript正则表达式 </title>
</head>
<body>
<script >
function regex()
{
var regex=/^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
var str = document.form1.name1.value;
var result = regex.test(str);
alert(result);
}
</script>
<form name=form1>
<input type=text name=name1 >
<input type=button onClick= "regex() " value= "test ">
</form>
</body>
</html>
js客户端验证
------解决方案-------------------- <SCRIPT LANGUAGE= "JavaScript ">
function isip(s){
var check=function(v){try{return (v <=255 && v> =0)}catch(x){return false}};
var re=s.split( ". ")
return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}
var s= "202.197.78.129 ";
alert(isip(s))
</SCRIPT>