Skip to content

Commit

Permalink
use better url detection (#16)
Browse files Browse the repository at this point in the history
* use better url detection

- now detects http://localhost and http://localhost:xxxx
- works with ip addresses

* accidentally used an invalid regex
  • Loading branch information
Flexusma authored Mar 29, 2023
1 parent 3c58ee1 commit aba5e5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/functions/webUtils/isValidURL.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
function isValidUrl(url) {
// eslint-disable-next-line no-useless-escape
const regex = new RegExp(/^[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/)

const regex = new RegExp('^([a-zA-Z]+:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR IP (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', // fragment locator
'i');
if (url.match(regex)) return true
return false
}

export default isValidUrl
export default isValidUrl

0 comments on commit aba5e5b

Please sign in to comment.