Skip to content
大纲

必须带端口号的网址

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

语法

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

参数

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

返回值

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

源码

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

例子

js
import { urlWithPortReg } from 'warbler-js';
const result1 = urlWithPortReg('http://www.warblerfe.top');
const result2 = urlWithPortReg('http://www.warblerfe.top:3000');
const result3 = urlWithPortReg('https://http://www.warblerfe.top:3000');

console.log(result1); // false
console.log(result2); // true
console.log(result3); // true

添加版本

1.2.0

Released under the MIT License.