?
Solved

Website URL validation

Posted on 2002-03-12
13
Medium Priority
?
1,032 Views
Last Modified: 2013-12-24
a quick one. i have a form where users can enter a web address. a link to their own website to be exact. users tend to enter all sorts of wrong things. so i need it to format it into the correct format.

ie:  somepeople might enter these:

1. <a href="www.mysite.com">mysite.com</a>
2. http://www.mysite.com

i need it to format that input, and insert into the database the correct info in this format:

www.mysite.com

whats the easiest or best way to do this?


0
Comment
Question by:M_Corkish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 37

Expert Comment

by:meverest
ID: 6856242
Somthing like:

<cfset fixedurl=ReReplace("#form.url#", "[^""/]*/*([^"" ])", "/1")>
<cfoutput>#fixedurl#</cfoutput>

?

if it doesn't work (likely!), i'll need to do some more work on my regex and try again!  :-}

cheers.
0
 

Author Comment

by:M_Corkish
ID: 6860170
Hmm, it doesn't quite work properly.. it spits out "/1" quite often. if you enter:

<a href="www.mysite.com">mysite.com</a>

it brings back:

/1"www.mysite.com">mysite.com

================
here is the full page i tested it on:

<cfif isdefined("form.url")>

<cfset fixedurl=ReReplace("#form.url#", "[^""/]*/*([^"" ])", "/1")>
<cfoutput>#fixedurl#</cfoutput>

</cfif>

<form action="test.cfm" method="post">
URL:
<input type="text" name="url">
<input type="submit" value="submit">

</form
0
 

Expert Comment

by:slingle
ID: 6860369
This isn't some long logical solution, but...  What I always do is put http:// as a label in front of the input field.  99.9% of the time, this keeps the user from entering the http (or html) in the field.  That way you get only the url and you control how it goes in your db.  

example:

<p>http://<input type="text" name="url"><br>
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Expert Comment

by:slingle
ID: 6860375
well i forgot experts exchange autmatically links urls so let me try my example again:

&lt;p&gt;http://<input type="text" name="url"&gt;&lt;br&gt;
0
 

Author Comment

by:M_Corkish
ID: 6860459
yeah, i have that.. but in the first day of running the site, people got it wrong.. even after saying "http://"

some people also try to enter <A href="www.mysite.com">mysite.com</a> on other comments and messages they post? is their a good way to deal with this?

0
 
LVL 11

Accepted Solution

by:
jimmy282 earned 400 total points
ID: 6860498
This works :-)

<cfset OriginalString = "http://the-whizkids.com">

Or

<Cfset OriginalString = "<a href=""http://the-whizkids.com""></a>">

Or

<cfset OriginalString = "the-whizkids.com">

<CFSCRIPT>
       OriginalString = ReReplaceNocase(OriginalString,"<a[^h]*href=""?([^"" ]*)""?[^>]*>([^<]*)</A>",
"\2","ALL");

OriginalString = ReRePlaceNoCase(OriginalString,"^(http|ftp|https)://","");

  </CFSCRIPT>

  <cfoutput>
  #OriginalString#  
  </cfoutput>
0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6860511
THIS
<Cfset OriginalString = "<a href=""http://the-whizkids.com""></a>">
should have been
<Cfset OriginalString = "<a  href=""http://the-whizkids.com"">the-whizkids.com</a>">

Jimmy
0
 

Author Comment

by:M_Corkish
ID: 6860546
Jimmy, it looks good, I changed the second example from:

<Cfset OriginalString = "<a href=""http://the-whizkids.com""></a>">

to:

<Cfset OriginalString = '<a href=""http://the-whizkids.com""></a>'>


substituting the double quotes for the single one. as it didn't work, due to the fact do body would actually enter in href=""www.blah.com"". using the single one works however in that case.

Thanks for the good stuff.  So what exact are the ReReplaceNoCase functions all about?  and the \2  for? and such?

0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6860590
These are Regualr Expressions.
Perl is the langauge which handles them best and CF really handles hem very differently. They are available in all languages though. ASP,PHP,CF, Java etc.

\2 means that the second match from the pattern found by the regular expression ","<a[^h]*href=""?([^"" ]*)""?[^>]*>([^<]*)</A>" which actually is the content between the starting and closing A tags.

HTH
Jimmy
0
 

Author Comment

by:M_Corkish
ID: 6860613
Cool, thanks for everything... ;-) i'm gonna have a look into that function now that i know where to start.

0
 
LVL 11

Expert Comment

by:jimmy282
ID: 6860620
Thanks for the points.
0
 

Author Comment

by:M_Corkish
ID: 6860634
no worries! hey, i just checked out your site.. 8) must really enjoy helping others out. it's good to see. ;-)

0
 
LVL 37

Expert Comment

by:meverest
ID: 6862576
sorry - got my '\' and '/' mixed up! i knew i would ... ;-)

cheers.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
What You Need to Know when Searching for a Webhost Provider
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question