JS Regular expression authentication IP list-Details: An input box in the page, you can enter 1 or more IPs, separated by commas

Source: Internet
Author: User

varisIp = function(){

     var regexp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;                   return function (value){          var valid = regexp.test(value);          if (!valid){ //首先必须是 xxx.xxx.xxx.xxx 类型的数字,如果不是,返回false              return false ;          }                   return value.split( ‘.‘ ).every( function (num){              //切割开来,每个都做对比,可以为0,可以小于等于255,但是不可以0开头的俩位数              //只要有一个不符合就返回false              if (num.length > 1 && num.charAt(0) ===  ‘0‘ ){                  //大于1位的,开头都不可以是‘0’                  return false ;              } else if (parseInt(num , 10) > 255){                  //大于255的不能通过                  return false ;              }              return true ;          });      } }(); var test_ip =  ‘123.12.123.1‘ ; //一个普通的ip alert(isIp(test_ip)); //返回true var test_ips =  ‘123.1.1.1,127.0.0.1,192.168.1.1‘ ; //多个IP,用逗号(,)隔开 var isTrue = test_ips.split( ‘,‘ ).every( function (ip){    return isIp(ip); //先将字符串按照逗号分成数组,在校验就可以了 }); alert(isTrue); //返回true,上面的ip全部正确

JS Regular Expression authentication IP list-Details: An input box in the page, you can enter 1 or more IPs, separated by commas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.