2022-01-12 12:54:04 +00:00
|
|
|
export const isValidURL = (url: string): boolean => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const pattern = new RegExp(
|
|
|
|
'^(https?:\\/\\/)?' + // 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_]*)?$',
|
|
|
|
'i'
|
|
|
|
); // fragment locator
|
2020-03-20 16:26:50 +00:00
|
|
|
return !!pattern.test(url);
|
|
|
|
};
|
2020-05-04 20:20:45 +00:00
|
|
|
|
2022-04-11 18:01:43 +00:00
|
|
|
// Use checkUseSsl: false only if server url starts with http://
|
|
|
|
export const isSsl = (url: string): boolean => !/http:\/\//.test(url);
|