Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Website URL validation

Posted on 2002-03-12
13
Medium Priority
?
1,037 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

636 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