From ac25e58d8470d3db4afe63d77d7ad71e64c50fb6 Mon Sep 17 00:00:00 2001 From: Aravind142857 Date: Tue, 6 Jun 2023 02:10:32 -0500 Subject: [PATCH] Stylistic additions --- index.css | 6 ++++- index.html | 19 +-------------- index.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ result.js | 69 ------------------------------------------------------ 4 files changed, 73 insertions(+), 88 deletions(-) delete mode 100644 result.js diff --git a/index.css b/index.css index 9fdd6fb..4d71084 100644 --- a/index.css +++ b/index.css @@ -29,10 +29,14 @@ li { } input.invalid { border-color: red; + border-style: solid; + border-width: medium; } input.valid { border-color: green; + border-style: solid; + border-width: medium } .mandatory { color: red; -} \ No newline at end of file +} diff --git a/index.html b/index.html index 43f5a39..2b3bad1 100644 --- a/index.html +++ b/index.html @@ -23,24 +23,7 @@
- - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/index.js b/index.js index e69de29..7b56b1a 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,67 @@ +const submit = document.getElementById("button"); +submit.addEventListener('click', validate); +function validate(e) { + e.preventDefault(); + + const url = document.getElementById("URL"); + const glink = document.getElementById("GLink"); + // if (!url) { + // /* Flag */ + // } + let valid = true; + const domainExp = new RegExp("http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+"); + const filepathExp = new RegExp("[a-zA-Z]+"); + let count = 0; + let index = -1; + let domain = ""; + let filepath = ""; + for (let i=0; i < url.value.length; i++) { + if (url.value.charAt(i) == '/') { + count++; + } + if (count == 3) { + index = i; + break; + } + } + if (count >= 3) { + domain = url.value.substring(0, index); + if (index == url.value.length - 1) { + filepath = url.value.charAt(index); + } else { + filepath = url.value.substring(index, url.value.length - 1); + } + alert("Domain is " + domain + " filepath is " + filepath); + } else { + domain = url.value; + } + console.log(domain); + if (domain.match(domainExp)) /** and is available? */{ + const error = document.getElementById("error"); + if (error.classList.contains("visible")) { + error.classList.remove("visible"); + } + if (url.classList.contains("invalid")) { + url.classList.remove("invalid"); + } + url.classList.add("valid"); + error.setAttribute('aria-hidden', true); + error.setAttribute('aria-invalid', false); + console.log("Valid"); + return valid; + } else { + + /*flag*/ + const error = document.getElementById("error"); + error.classList.add("visible"); + + //error.classList.add("hidden"); + if (url.classList.contains("valid")) { + url.classList.remove("valid"); + } + url.classList.add("invalid"); + error.setAttribute('aria-hidden', false); + error.setAttribute('aria-invalid', true); + } + +} \ No newline at end of file diff --git a/result.js b/result.js deleted file mode 100644 index cf6ad95..0000000 --- a/result.js +++ /dev/null @@ -1,69 +0,0 @@ -const submit = document.getElementById("button"); -submit.addEventListener('click', validate); -function validate(e) { - e.preventDefault(); - - const url = document.getElementById("URL"); - const glink = document.getElementById("GLink"); - // if (!url) { - // /* Flag */ - // } - let valid = true; - const domainExp = new RegExp("http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+"); - const filepathExp = new RegExp("[a-zA-Z]+"); - let count = 0; - let index = -1; - let domain = ""; - let filepath = ""; - for (let i=0; i < url.value.length; i++) { - if (url.value.charAt(i) == '/') { - count++; - } - if (count == 3) { - index = i; - break; - } - } - if (count >= 3) { - domain = url.value.substring(0, index); - if (index == url.value.length - 1) { - filepath = url.value.charAt(index); - } else { - filepath = url.value.substring(index, url.value.length - 1); - } - alert("Domain is " + domain + " filepath is " + filepath); - } else { - domain = url.value; - } - console.log(domain); - if (domain.match(domainExp)) { - const error = document.getElementById("error"); - if (error.classList.contains("visible")) { - error.classList.remove("visible"); - } - //error.classList.add("hidden"); - if (url.classList.contains("invalid")) { - url.classList.remove("invalid"); - } - url.classList.add("valid"); - //url.classList.add("valid"); - error.setAttribute('aria-hidden', true); - error.setAttribute('aria-invalid', false); - console.log("Valid"); - return valid; - } else { - - /*flag*/ - const error = document.getElementById("error"); - error.classList.add("visible"); - - //error.classList.add("hidden"); - if (url.classList.contains("valid")) { - url.classList.remove("valid"); - } - url.classList.add("invalid"); - error.setAttribute('aria-hidden', false); - error.setAttribute('aria-invalid', true); - } - -} \ No newline at end of file