Files
itooldog/public/static/script/func.js
T
2023-03-22 11:41:09 +08:00

21 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function check_is_ip(ip) {
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
return reg.test(ip);
}
function check_is_url(url) {
  const strRegex = '^((https|Net)://)?'//(https或http或ftp):// 可有可无
  + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 3位数字.3位数字.3位数字.3位数字
  + '|' // 允许IP和DOMAIN(域名)
  + '([\\w_!~*\'()-]+\\.)*' // 域名- 至少一个[英文或数字_!~*\'()-]加上.
  + '\\w+\\.' // 一级域名 -英文或数字 加上.
  + '[a-zA-Z]{1,6})' // 顶级域名- 1-6位英文
  + '(:[0-9]{1,5})?' // 端口- :80 ,1-5位数字
  + '((/?)|' // url无参数结尾 - 斜杆或这没有
  + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$';//请求参数结尾- 英文或数字和[]内的各种字符
  const re = new RegExp(strRegex, 'i'); // 大小写不敏感
  if (re.test(encodeURI(url))) {
    return true;
  }
  return false;
}