<html> <head> <title><a href=‘http://js.zz5u.net‘><u>JavaScript</u></a>用正则验证IP地址格式是否正确_网页代码站(www.6a8a.com)</title> </head> <body> <script language="javascript"> function f_check_IP() { var ip = document.getElementById(‘reg_ip‘).value; var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;//正则表达式 if(re.test(ip)) { if( RegExp.$1<256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true; } alert("IP有误!"); return false; } </script> <form method="post" action="" onsubmit="return f_check_IP()"> 您的IP:<input type="text" id="reg_ip" name="reg_ip"> <input type="submit" name="submit" value="提交"> </form> <br /> </body> </html>
时间: 2024-12-12 05:24:18