JavaScript regular expression to validate URL

var expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi;
var regex = new RegExp(expression);
var t = 'www.facebook.com';

if (t.match(regex)) {
  alert("Successful match");
} else {
  alert("No match");
}
Published
Categorized as JavaScript

By Santosh Kumar Shah

I am JavaScript developer.

Leave a comment

Your email address will not be published. Required fields are marked *