Skip to content
Advertisement

How to check if the URL contains any number or empty?

Hi everyone please I need you’re help !!

How could I do something like this:

<script type="text/javascript">
    $(document).ready(function() {
       if (window.location.href.indexOf(" ") > -1) {
         alert("your url index is empty");
       }
    });
</script>

I need to know whene my Url index contain something (ID number) or empty.

Advertisement

Answer

This should get the job done:

   if (window.location.href.match(/d+/g)) {
     alert("your url index is empty");
   }
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement