From 2542cd4754996b94c2be1a64a7cdf67b4997bb33 Mon Sep 17 00:00:00 2001 From: kheenvraj Date: Fri, 2 Oct 2020 14:06:46 +0530 Subject: [PATCH] Validate a URL --- collections/validator/validate-a-url.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 collections/validator/validate-a-url.md diff --git a/collections/validator/validate-a-url.md b/collections/validator/validate-a-url.md new file mode 100644 index 00000000..0c07de4f --- /dev/null +++ b/collections/validator/validate-a-url.md @@ -0,0 +1,8 @@ +~~~ javascript +const is_valid_url = (url) => !(!(/^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/.test(url))); + +//Examples +is_valid_url("http://example.in"); // true +is_valid_url("https://www.example.com"); // true +is_valid_url("www.example.com"); // true +~~~ \ No newline at end of file