Click here to Skip to main content
16,022,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to do the validation for the URL

"https://myapp.com/mycompanyname/"
There mycompanyname is mandatory , It can be any name. I tried the below code:

/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-]))?/
But mycompanyname is not validating. How can we achieve it?

Thanks

What I have tried:

I tried the below code:

/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-]))?/
Posted
Updated 19-Dec-16 22:49pm
Comments
Patrice T 14-Dec-16 0:59am    
"is not validating" is not informative.
Show examples of url that will match and some that don't.

Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
 
Share this answer
 
This is working fine for me:

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


Hope this will work for you.

NOTE: Please mark answer if it help you.
 
Share this answer
 
Comments
jaideepsinh 18-Apr-18 8:31am    
This will accept "http://www.com" which is not valid url.
And it will also accept single or more then W in any url like "http://wwwww.test.com"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900