How can I create an unavailable urls filter? (javascript)

0

Hello, I wanted to know how I can filter certain subdomains that would mimic the brand of my company eg in a free hosting the user types a subdomain to the address of their site. if he types a subdomain as just the word " blog " or " forum ", " news ". it would appear a warning that this subdomain is invalid. I would like a client-side script, and only to prevent users from creating sites simulating the brand of my company like eg: it could not create blog.mydomain.xy, filter these words, but when typed "blog21.mydomain.xy "this warning does not appear.

    
asked by anonymous 09.01.2018 / 04:54

1 answer

1

You can create an array in js and use the indexOf method. Ex:

const subdomainDisabled = ["blog", "news", "cdn"];
const input = document.querySelector("input");
const btn = document.querySelector("button");

btn.addEventListener("click", function() {
  if (subdomainDisabled.indexOf(input.value) >= 0) {
    alert("Choose another subdomain");
    input.value = "";
  } else {
    $('#ID-DO-MODAL').modal("show");
  }
});
<input type="text" id="subdomain" />
<button type="button">Register</button>
    
09.01.2018 / 06:14