列表

详情


FED3. 合法的URL

描述

请补全JavaScript代码,要求以Boolean的形式返回字符串参数是否为合法的URL格式。
注意:
1. 协议仅为HTTP(S)

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1685ms, 内存消耗: 77772KB, 提交时间: 2022-02-10

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _isUrl = url => {\n                // 补全代码\n                  const reg = /^(http|https)?:\\/\\/\\w+(\\.[\\w.-])+\\.[a-zA-Z]{2,6}/g\n                return reg.test(url)\n                \n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1733ms, 内存消耗: 77772KB, 提交时间: 2021-12-14

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _isUrl = url => {\n                // 补全代码\n                let reg = /^https?:\\/\\/[a-z0-9A-Z_$][\\w-]*(\\.[\\w-]+)+(\\:\\d+)?(\\/\\w+)*(\\?\\w+=.*(\\&\\w+=.*)*)?/g;\n                return reg.test(url);\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1739ms, 内存消耗: 77772KB, 提交时间: 2021-12-31

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _isUrl = url => {\n                // 补全代码\n                 let reg = /^https?:\\/\\/[a-z0-9A-Z_$][\\w-]*(\\.[\\w-]+)+(\\:\\d+)?(\\/\\w+)*(\\?\\w+=.*(\\&\\w+=.*)*)?/g;\n                return reg.test(url);\n                \n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1739ms, 内存消耗: 77816KB, 提交时间: 2021-12-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n        const _isUrl = url => {\n  return /^((http|https):\\/\\/)?(([A-Za-z0-9]+-[A-Za-z0-9]+|[A-Za-z0-9]+)\\.)+([A-Za-z]+)(:\\d+)?(\\/.*)?(\\?.*)?(#.*)?$/.test(url)\n}\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77772KB, 提交时间: 2022-01-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _isUrl = url => {\n                // 补全代码\n                return /^http(s)+/.test(url)\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题