必须带端口号的网址

验证网址,必须带有端口号,支持IP

语法

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

参数

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

返回值

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

源码

  1. const urlWithPortReg = (value) => {
  2. const reg = /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/;
  3. return reg.test(value);
  4. };

例子

  1. import { urlWithPortReg } from 'warbler-js';
  2. const result1 = urlWithPortReg('http://warblerjs.duwanyu.com')
  3. const result2 = urlWithPortReg('http://warblerjs.duwanyu.com:3000')
  4. const result3 = urlWithPortReg('https://warblerjs.duwanyu.com:3000')
  5. console.log(result1) // false
  6. console.log(result2) // true
  7. console.log(result3) // true