Simple JavaScript RegEx to Parse Domain Name

There are many JavaScript resources to parse an URL in JavaScript RegEx. And parsing the domain main is easy since there's a lot of trick. This is useful for checking whether there is a third party domain involved in a page.

Today, jsB@nk would like to present you another JavaScript example code to parse an URL address using JavaScript RegEx. This JavaScript object is built into 2 JavaScript public methods, we can use them to get domain root of an URL address, or check if whether domain is exist.

Other JavaScript RegEx example codes you should try:
- getElementsByClassName: Simple Shorthand Way to Get HTML Element by className with RegExp
- JavaScript RegEx Example Code for Text Input Limitations
- Built-in JavaScript RegEx APIs
- RegExp Validation


Sampled by © JavaScriptBank.com

Usages:

document.write(UriParser.parseRootDomain("http://user:password@www.truste.com.ca:80/pathname?querystring&key=value#fragment"));
document.write(UriParser.parseRootDomain("http://google.com.ph/pathname?querystring&key=value#fragment"));
document.write(UriParser.parseRootDomain("http://www.google.com/pathname?querystring&key=value#fragment"));
document.write(UriParser.parseRootDomain("http://google.com/pathname?querystring&key=value#fragment"));
document.write(UriParser.parseRootDomain("http://localhost/pathname?querystring&key=value#fragment"));
document.write(UriParser.parseRootDomain("localhost"));
document.write(UriParser.parseRootDomain("http://192.168.1.1/pathname?querystring&key=value#fragment"));
document.write(UriParser.isSameDomain("http://www.google.com/pathname?querystring&key=value#fragment", "http://adsense.google.com/?x=123123")) document.write(UriParser.isSameDomain("http://www.blogger.com/navbar.g?targetBlogID=5856931630868336061&blogName=TeamPilipinas.info&publishMode=PUBLISH_MODE_HOSTED&navbarType=BLACK&layoutType=LAYOUTS&searchRoot=http%3A%2F%2Fteampilipinas.info%2Fsearch&blogLocale=en_PH&homepageUrl=http%3A%2F%2Fteampilipinas.info%2F", "blogger.com"));

Results:


2000+ free JavaScripts
at www.JavaScriptBank.com