Click here to Skip to main content
15,917,642 members
Please Sign up or sign in to vote.
1.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
5. it validate this type of domail also

.firm.in
.co.uk
.co.cc

In www.example.com after example dot .. it contain [2,4]+[.]+[2] letter of [a-z]
Posted
Comments
Shreyas Tg 17-Feb-14 1:42am    
http://stackoverflow.com/questions/9289007/regular-expression-for-url-validation

^(http[s]?://)?[w]{3}[.]([a-z0-9]+[.])+([a-z]{2,4}[.])([a-z]{2})$
 
Share this answer
 
v2
Comments
DeathVally 21-Feb-14 7:21am    
not only for above 3-4 domain but for all. above are only examples.
i mean to say url contain 3 char domain [or] ---2-4char+[.]+2char total{5,7} char---
Peter Leow 21-Feb-14 7:46am    
It is clearer now. See amended solution.
Try this:

^((http|ftp|https|www)://)?([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?$
 
Share this answer
 
Comments
DeathVally 17-Feb-14 1:56am    
First read Question Carefully.
Malli_S 17-Feb-14 2:16am    
I've given you a sample, try implementing the required solution from it.
DeathVally 17-Feb-14 3:20am    
if i m able to implement it ... then y can i post here.

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