Last active
July 13, 2017 09:14
-
-
Save tomieric/66f9ff5a0f85a0c4da4ebcff92dcc1ad to your computer and use it in GitHub Desktop.
是否非法网址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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