mirror of
https://github.com/Lissy93/web-check.git
synced 2025-01-08 23:38:30 +01:00
fix url bug
This commit is contained in:
parent
fe1e74a22f
commit
07656c6fea
@ -7,13 +7,12 @@ export type AddressType = 'ipV4' | 'ipV6' | 'url' | 'err' | 'empt';
|
|||||||
|
|
||||||
/* Checks if a given string looks like a URL */
|
/* Checks if a given string looks like a URL */
|
||||||
const isUrl = (value: string):boolean => {
|
const isUrl = (value: string):boolean => {
|
||||||
const urlPattern = new RegExp(
|
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
|
||||||
'^(https?:\\/\\/)?' +
|
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name
|
||||||
'(?!([0-9]{1,3}\\.){3}[0-9]{1,3})' + // Exclude IP addresses
|
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address
|
||||||
'(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*' + // Domain name or a subdomain
|
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path
|
||||||
'([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$', // Second level domain
|
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string
|
||||||
'i' // Case-insensitive
|
'(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator
|
||||||
);
|
|
||||||
return urlPattern.test(value);
|
return urlPattern.test(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user