...

View Full Version : Regular expression not working.



Scriptdaemon
07-15-2007, 05:45 AM
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.




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;
}

rwedge
07-15-2007, 06:28 AM
Give this a try:
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;
}

Scriptdaemon
07-15-2007, 06:34 AM
Worked. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum