Skip to content

Instantly share code, notes, and snippets.

@tomieric
Last active July 13, 2017 09:14
Show Gist options
  • Save tomieric/66f9ff5a0f85a0c4da4ebcff92dcc1ad to your computer and use it in GitHub Desktop.
Save tomieric/66f9ff5a0f85a0c4da4ebcff92dcc1ad to your computer and use it in GitHub Desktop.
是否非法网址
function IsInvalid (regs = []) {
/* var regs = [
/^(((http|https):)?(\/\/)?(([^=\?])*\.)?tomieric\.com)/g,
/^(((http|https):)?(\/\/)?mlogin\.tmpal\.com)/g
] */
/* var result = false
regs.forEach(function(reg) {
result = result || reg.test(url)
})
return result*/
return url => !!regs.find(reg => reg.test(url))
}
const isInvalid = IsInvalid([
/^(((http|https):)?(\/\/)?(([^=\?])*\.)?tomieric\.com)/g,
/^(((http|https):)?(\/\/)?mlogin\.tmpal\.com)/g
])
// 测试
var testCase = [
'http://123.tomieric.com', // true
'//123.tomieric.com', // true
'//123tomieric.com', // false
'http://tomieric.com', // true
'https://tomieric.com', // true
'http://123.tomieric2.com', // false
'https://123.tomieric.com', // true
'http://mlogin.tmpal.com', // true
'https://mlogin.tmpal.com', // true
'https://baidu.com?t=https://www.tomieric.com', // false
'https://www.baidu.com/?f=m.tomieric.com', // false
'https://www.baidu.com/?m.tomieric.com' // false
]
testCase.forEach(function (tCase) {
console.log(tCase, isInvalid(tCase))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment