Skip to content

Instantly share code, notes, and snippets.

@HereChen
Created June 21, 2017 01:54
Show Gist options
  • Save HereChen/5253caa908ff1b6f6da3792111f5c90e to your computer and use it in GitHub Desktop.
Save HereChen/5253caa908ff1b6f6da3792111f5c90e to your computer and use it in GitHub Desktop.
// validate url
// 检查 url 是否合法
// https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
// http://regexr.com/3e6m0
function isUrl(url) {
return /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment