Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Regular expression not working.

    I'm obviously doing something wrong, but could anyone tell me what it is? I have this function to find the page number from the url, or return with a "1." The commented line contains the problem, as if the page is not 1, it returns 1 anyway.

    Code:
    function getPageNo() {
    	var url = window.location.href;
    	if(url.indexOf("?") > -1) {
    		var page, query = url.substr(url.indexOf("?") > -1);
    		query = query.split("&");
    		for(var a = 0; a < query.length; a++) {
    			if(query[a].indexOf("page=")) {
    				page = query[a].split("=");
    				break;
    			}
    		}
    //		if(page[1] == /^\d+$/)
    			return page[1];
    	}
    	return 1;
    }

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Give this a try:
    Code:
    function getPageNo() {
    var url = window.location.href;';
      if(url.indexOf("?") != -1) {
          var page, query = url.substr(url.indexOf("?"), url.length -1);
          query = query.split("&");
                for(var a = 0; a < query.length; a++) {
                   if(query[a].match(/page/i)) {
                              page = query[a].split("=");
                              break;
                   }
                }
         if (page[1].match(/^\d+$/))  return page[1];
      }
    return 1;
    }

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Worked. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •