Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I need a ergec that validates the following:
http://google.com
https://googwl.com
http://www.google.com
https://www.google.com
www.google.com
www.google.com.eg
www.google.ca

and doesn't validate the following:
google
www.google
google.com
Posted
Comments
Ankur\m/ 18-Feb-14 7:11am    
So write one! Take help of regex writing tools available online (and there are many that you can download).
Member 10304621 18-Feb-14 7:56am    
i'm new in asp.net, i'm not strongly aware of regex to be able to create one
I've searched in this line but I couldn't find my answer
http://www.regxlib.com/
Ankur\m/ 18-Feb-14 12:45pm    
I do understand that you are new to it. But if you ask people for help rather than trying yourself, you will never learn. As I have already told that there are lot of tools available which will help you write regular expression and validate samples against it. Try them out.
And there is joy to doing something you do not know. Try it and you will know! :)
thatraja 18-Feb-14 7:38am    
google.com is valid one IMO. Newbies/normal people don't type protocol/www. before the urls

Please check below links for more info.

URL Validator

How to validate URLs with regular expressions

UPDATE

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
 
Share this answer
 
v2
Comments
Member 10304621 18-Feb-14 7:58am    
this allows www.google
Sampath Lokuge 18-Feb-14 8:37am    
I have updated the solution.Please check that.
^((http|https)://)?([\w-]+\.)+[\w]+(/[\w- ./?]*)?$
 
Share this answer
 
Comments
Member 4058461 21-May-15 6:05am    
This URL is getting validated https://www.google, but that should not be.

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