We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e5aab07 commit 3f3acc3Copy full SHA for 3f3acc3
src/util/format.ts
@@ -52,9 +52,14 @@ export function formatDate(date: Date): string {
52
}
53
54
// 校验是否 url 格式
55
-export function isHttpOrHttps(url: any) {
56
- const regex = /^(https?):\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/;
57
- return regex.test(url);
+export function isHttpOrHttps(url: string): boolean {
+ if (url.trim() === '') return false;
+ try {
58
+ const parsed = new URL(url);
59
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:';
60
+ } catch {
61
+ return false;
62
+ }
63
64
65
const innerTemplate = ['m0', 'm1', 'm2', 'm3']
0 commit comments