Website URL validation in JavaScript | Example code

With Regular expression you can easily verify valid Website URL in JavaScript.


string.match(/(http(s)?:\/\/.)?(www\.)?[[email protected]:%._\+~#=]{2,256}\.[a-z]{2,6}\b([[email protected]:%_\+.~#?&//=]*)/g);

Website URL validation in JavaScript

HTML example code JavaScript function to check whether a given value is an valid website URL or not. It will validate URL with or without HTTP/HTTPs.


		function isValidURL(string) {
			var res = string.match(/(http(s)?:\/\/.)?(www\.)?[[email protected]:%._\+~#=]{2,256}\.[a-z]{2,6}\b([[email protected]:%_\+.~#?&//=]*)/g);
			return (res !== null)




Website URL validation in JavaScript

Do comment if you have any doubts and suggestion on this JS URL code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.