Files
twenty/front/src/utils/is-url.ts
Charles Bochet e61c263b1a Misc fixes
2023-08-10 17:16:27 -07:00

15 lines
420 B
TypeScript

import { isDefined } from './isDefined';
export function isURL(url: string | undefined | null) {
const pattern = new RegExp(
'^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$',
'i',
);
return isDefined(url) && !!pattern.test(url);
}