whisher
1
Hi,
I’ve to check if a string contains the hostname
my 5 cents and it seems to work but not being at all
a regex guru …
var re = new RegExp(window.location.hostname,'i');
alert(re.test(str));
str can be like:
http://www.MYdomain.com/
www.mydomain.com/action/id/12
www.mydomain.com?id=12
sub.mydomain.com
and so on …
Hi,
That does work.
var l = window.location.hostname;
var regex = new RegExp(l, 'i');
var options = [
'http://www.mydomain.com/',
'http://www.mydomain.com',
'www.mydomain.com/',
'http://www.MYdomain.com/',
'www.mydomain.com/action/id/12',
'www.mydomain.com?id=12',
'sub.mydomain.com'
]
for (var i=0, ii=options.length; i<ii; i++) {
alert(regex.test(options[i]));
}
whisher
3
Thanks everybody for the reply
@markbrown4 I wanted be sure
@Stomme_poes
var l = window.location.hostname;
I had no idea what you were talking about, so I had written a regex : )
[ot]
Man I’m already getting bogged on this tagging thing. Trying to find my mail just got harder.[/ot]
whisher
5