Skip to content Skip to sidebar Skip to footer

Url Validation Using Javascript

I'm trying to use regex to validate user entered URLs. I came up with this regex: function is_valid_url(url) { return url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^

Solution 1:

Easiest option: use a regex that works.

(((http|ftp|https):\/\/)|www\.)[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#!]*[\w\-\@?^=%&/~\+#])?

Regexr:http://regexr.com?2tpo8

Post a Comment for "Url Validation Using Javascript"