Click here to Skip to main content
15,910,773 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
Need Regular Expression for url validation

Rules:

1. It should validate even if (http or https) is included or not.
2. it not contain other protocols like ftp, mailto
3. It should not contain sub domain URL's and "/" after .com
4. www is must included in url
Posted
Comments
So, what have you tried?
DeathVally 15-Feb-14 2:08am    
(?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9])(.[a-z]|[A-Z]{2,3}$)*)

Thank u for response.
What is the problem with this?
DeathVally 15-Feb-14 2:25am    
not work properly and i don't know anything about regex.

Try this:
^(http[s]?://)?[w]{3}[.]([a-z0-9]+[.])+[a-z]{1,3}$

Convert the url into small case first before applying this regex pattern.
 
Share this answer
 
v2
Comments
DeathVally 15-Feb-14 2:44am    
this is 90% done ... but just 1 problem and that is http or https is optional in input.
read 1st rule of question.

Thank u for help.
Peter Leow 15-Feb-14 3:23am    
Amended to take care of optional http or https
DeathVally 16-Feb-14 4:47am    
Working ... Thank u 4 Help.
DeathVally 17-Feb-14 0:01am    
what can i do with .co.uk or .firm.in ... please modify this regex for www.example.firm.in | www.example.co.uk .... after example dot it contain {2,4}+dot+{2} letter
Peter Leow 17-Feb-14 0:26am    
You should post it as a new question.
 
Share this answer
 
Comments
Sampath Lokuge 15-Feb-14 2:35am    
+5 Nice one mate :)
DeathVally 15-Feb-14 2:37am    
allowed sub domains and http or https is must .... this both case is reverse regarding to my requirement. please read rules of question again.

Thank u for your Response.
 
Share this answer
 
Comments
JoCodes 15-Feb-14 2:41am    
5!
Sampath Lokuge 15-Feb-14 2:47am    
Thanks JoCodes :)

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