Web page url validation

Viewed 26

im trying to filter an input text of a form to only allow valid url for webpage, i mean something like example.com would be valid, either with the https field or not

i've been using a function in js to check another domains that i dont want to be valid the function is like that:

function validateWeb(){

    var form = document.forms['WebToLeads4207845000109425073'];
    var webFld = form.querySelectorAll('[name="Website"]');

    if(webFld.indexOf('google.')== -1 && webFld.indexOf('facebook.')== -1 && webFld.indexOf('tiktok.')== -1 && webFld.indexOf('tiktok.')== -1 && webFld.indexOf('instagram.')== -1 ){

      return true;
    }else{
      return false;
    }

  }

how can i check the url is well composed?

1 Answers

To check whether a url is a well-formed url you might consider using a regex. Before proceeding to define such a regex, we should open a chapter on regexes. Maybe it is better not to open it ahaha

Here you can find the regex for match URL

What is a good regular expression to match a URL? [duplicate]

You just have to use it directly leaving the confirmation part that you used to filter the domains

Related