Skip to content

isValidUrl 校验 URL

function isValidUrl(value: string): boolean

校验字符串是否符合标准 HTTP/HTTPS 网页地址格式。支持域名、localhost、IPv4、端口、路径、查询参数和 hash。

参数

参数名说明类型默认值
value待校验的字符串string必填

返回值

返回值说明类型
resultURL 格式有效时返回 true,否则返回 falseboolean

示例

typescript
import { isValidUrl } from '@mingto/tools'

isValidUrl('https://example.com/path?a=1') // true
isValidUrl('http://localhost:3000') // true
isValidUrl('/relative/path') // false

注意事项

  • 仅校验 http://https:// 地址。