mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 10:19:04 +08:00
merge: Add ValidateUrl in String (#856)
* Add ValidateUrl in String * change regex * Bug fix
This commit is contained in:
13
String/ValidateUrl.js
Normal file
13
String/ValidateUrl.js
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @function ValidateURL
|
||||
* @description validate the URL.
|
||||
* @param {String} url - The input URL string
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const validateURL = (url) => {
|
||||
const URL_PATTERN = /^(https?:\/\/(?:www\.|(?!www))[^\s.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})$/gi
|
||||
|
||||
return URL_PATTERN.test(url)
|
||||
}
|
||||
|
||||
export { validateURL }
|
Reference in New Issue
Block a user