ip-v4

验证 ip-v4,允许携带端口。

语法

  1. import { ipv4Reg } from 'warbler-js';
  2. const result = ipv4Reg(value);

参数

  • value (String) : 待验证字符串。

返回值

Boolean : 是否通过验证,true 通过验证, false 没有通过验证。

源码

  1. const ipv4Reg = (value) => {
  2. const reg = /^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/;
  3. return reg.test(value);
  4. };

例子

  1. import { ipv4Reg } from 'warbler-js';
  2. const result1 = ipv4Reg('127.16.0.0')
  3. const result2 = ipv4Reg('127.0.0.1:8080')
  4. console.log(result1) // true
  5. console.log(result2) // false