Appearance
isValidUrl 校验 URL
function isValidUrl(value: string): boolean
校验字符串是否符合标准 HTTP/HTTPS 网页地址格式。支持域名、localhost、IPv4、端口、路径、查询参数和 hash。
参数
| 参数名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| value | 待校验的字符串 | string | 必填 |
返回值
| 返回值 | 说明 | 类型 |
|---|---|---|
| result | URL 格式有效时返回 true,否则返回 false | boolean |
示例
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://地址。