Subscribe to Youtube channel

Regular expression for validating URL in Javascript

I was looking for a decent regular expression to validate URLs that were entered as user input with.
After lots of searching on google i got the perfect solution which satisfy my requirement of my current assignment
Following is the regular expression for validating URL (Valid URL Regular Expression) a have used which worked perfectly.

^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$

Following is the pattern results for the same
  • https://www.test.com   -Passed
  • http://www.test.com   -Passed
  • www.test.com   -Passed
  • test.com   -Passed
  • http://blog.test.com   -Passed
  • http://www.test.com/product   -Passed
  • http://www.test.com/products?id=1&page=2   -Passed
  • http://www.test.com#up   -Passed
  • http://255.255.255.255   -Passed
  • 255.255.255.255   -Passed
  • http://invalid.com/perl.cgi?key= | http://web-site.com/cgi-bin/perl.cgi?key1=value1&key2   -Failed
  • http://www.site.com:8008   -Passed

Comment if you like it!!

Comments

Popular posts from this blog

Root your Gingerbread 2.3.4 android Mobile Phone

Restore the lost focus of Auto post back controls in asp.net update Panel control

Disable backspace key using Jquery

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Implement Nlog in .Net core MVC application part 1

Angular User Session Timeout example step by step

Devexpress Datebox date formatting in angular 6 with example

How to Import CSV File and bind csv file data to gridview in asp.net using c#

Add Comma automatically while entering amounts in textbox using Javascript