当前位置:网站首页>JS regular détermine si le nom de domaine ou le chemin de port IP est correct
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
2022-04-23 15:47:00 【Victoria Junior...】
AdoptionjsPour juger régulièrementipChemin du porthttp://127.0.0.1:3000/listOuhttps://www.baidu.com:8080/listOui Non
const reg = new RegExp(/^http(s)?:\/\/((www\.)?[a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9]{0,62})|(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[0-9])\.((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.){2}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d))\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])\/+[a-zA-Z0-9]/)
reg.test(“https://www.aaaa.com:2000/105”) // true
reg.test(“https://127.0.0.1:2000/105”) // true
reg.test(“https://127.0.0.1:2000/System/list”) // true
reg.test(“https://127.0.0.1:2000/dict/list”) // true
reg.test(“http://127.0.0.1:2000/dict/list”) // true
L'intégralité de l'étalonnage url, Vous pouvez utiliser la méthode suivante pour extraire ip、Port.Chemin
// AccèsipAdresse、Port、Lu Jin
getUrlComponent (url) {
let res = {
}
if (url.indexOf('//') !== -1 || url.indexOf(':') !== -1 || url.indexOf('.') !== -1) {
// Ne pas intercepter http
let str = url.indexOf('//') !== -1 ? url.substr(url.indexOf('//') + 2) : url
res.ip = str.indexOf(':') !== -1 ? str.substr(0, str.indexOf(':')) : str.indexOf('/') !== -1 ? str.substr(0, str.indexOf('/')) : str
res.port = str.indexOf('/') !== -1 ? str.slice(str.indexOf(':') + 1, str.indexOf('/')) : str.substr(str.indexOf(':') + 1)
res.path = res.port !== '' && str.indexOf(res.port) !== -1 ? str.substr(str.indexOf(res.port) + res.port.length) : str.indexOf('/') !== -1 ? str.substr(str.indexOf('/')) : ''
}
return res
}
版权声明
本文为[Victoria Junior...]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231547082639.html
边栏推荐
- pgpool-II 4.3 中文手册 - 入门教程
- 单体架构系统重新架构
- Upgrade MySQL 5.1 to 5.611
- IronPDF for .NET 2022.4.5455
- shell脚本中的DATE日期计算
- MySQL Cluster Mode and application scenario
- Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
- Neodynamic Barcode Professional for WPF V11.0
- ICE -- 源码分析
- Independent operation smart farm Innovation Forum
猜你喜欢

新动态:SmartMesh和MeshBox的合作新动向

MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问

基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践

CVPR 2022 quality paper sharing

MySQL optimistic lock to solve concurrency conflict

Codejock Suite Pro v20. three

Mobile finance (for personal use)

API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)

考试考试自用

【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
随机推荐
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
Deletes the least frequently occurring character in the string
Go language slice, range, set
Codejock Suite Pro v20. three
Why disable foreign key constraints
Spark 算子之distinct使用
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
Neodynamic Barcode Professional for WPF V11. 0
携号转网最大赢家是中国电信,为何人们嫌弃中国移动和中国联通?
多线程原理和常用方法以及Thread和Runnable的区别
IronPDF for . NET 2022.4.5455
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
Why is IP direct connection prohibited in large-scale Internet
大型互联网为什么禁止ip直连
为啥禁用外键约束
Spark 算子之filter使用
Extract non duplicate integers
Basic concepts of website construction and management
leetcode-396 旋转函数