Connecting Tech Pros Worldwide Forums | Help | Site Map

help needed in Custom Validator in ASP.NET

KalariaNitya's Avatar
Member
 
Join Date: Apr 2008
Posts: 34
#1: Oct 6 '08
Hello all,

i want to use regular expression of Internet URL which is mentioned in asp.net
(http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)

but, i don't want http:// so for that how can i make that regular expression. can anybody help me?

e.g. i want www.sharebrochure.com instead of http://sharebrochure.com

i had done something like \w+([-+.']\w+)*.\w+([-.]\w+)*\.\w+([-.]\w+)*
but it can't give proper validation

plz help me..

thanking u in advanced..

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Oct 6 '08

re: help needed in Custom Validator in ASP.NET


w{3}\.
Looks for 3 "w'"s followed by a "."

\w+\.
Looks for 1 or more letters or digits followed by a "."

(\w+\.)+

Looks for 1 or more words (containing digits) followed by a "."

Therefore the following regex will match www.hotmail.something.or.other.com

(w{3}\.)(\w+\.)+(\w+)


However this Regex will not fully meet the requirements that you are looking for.

You are going to have to look at what makes a valid URL address (I think that underscores "_" are valid....etc) and create a Regex based on these rules.

You'll have to break each section down as I have here and describe what you are looking for. A helpful tool in determining if your Regex works can be found here. There are many many other tools out there.

-Frinny
Reply