JS判断IP的正则表达式

<html>
<head>
    <title>最简洁的IP判断正则表达式</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="zh-CN" />
    <script type="text/javascript" src="https://files.cnblogs.com/Zjmainstay/jquery-1.6.2.min.js"></script>
</head>
<body>
IP字段: <input type="text" id="ip" />
判断结果:<input type="text" id="result" />
<script type="text/javascript">
$(document).ready(function(){
function validateIP(str){ return !!str.match(/^((25[0-5]|2[0-4]\d|[01]?\d\d?)($|(?!\.$)\.)){4}$/); } $("#ip").blur(function(){ var m = validateIP($(this).val()); m = m || 'null'; $("#result").val(m); }); }); </script> </body> </html>

结果:

 IP字段:  判断结果:

posted on 2017-03-23 10:21  LJD泊水  阅读(824)  评论(0编辑  收藏  举报