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

x
?
Solved

need to validate blogspot url

Posted on 2009-07-16
10
Medium Priority
?
294 Views
Last Modified: 2012-05-07
i need to validate the url which should contain blogspot word....using javascript

mathches
http://www.abc.blogspot.com
www.abc.blogspot.com
abc.blogspot.com

NON-matches
http://www.blogspot.com (see there is No user Name)
http://www.abc.blogspot.com/sdfsf( There should not be any thing after .com)
http://www.abc.blogspot.in(other than .com no other domain should be supported)
fdsfsfsdf.com (no proper url..)

Please suggest ....
0
Comment
Question by:Rajar Ahmed
[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
  • 4
  • 4
  • 2
10 Comments
 
LVL 2

Expert Comment

by:SaWey
ID: 24869601
what characters are allowed in the username?
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24869699
characters which accepts blogspot website i think mostly alphanumeric .ll be fair enough..!
0
 
LVL 2

Expert Comment

by:SaWey
ID: 24869874
I hope this one does it for you:
if (blogspotURL.match(/^(?:(?:http:\/\/|)(?:www\.|)[^w\/][\-A-Z0-9]+\.blogspot\.com[^\/a-zA-Z0-9.])$/i)) {
	// Successful match
} else {
	// Match attempt failed
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24870018
if (document.getElementById("blogspottextbox").value.match(/^(?:(?:http:\/\/|)(?:www\.|)[^w\/][\-A-Z0-9]+\.blogspot\.com[^\/a-zA-Z0-9.])$/i)) {
     alert("success");
 } else {
     alert("wrong");
 }
     
 tried with these test data's
 http://www.adsd.blogspot.com
 adsd.blogspot.com
 www.adsd.blogspot.com
 
 all i got wrong alert ...but these are correct urll y .??
:(
0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 2000 total points
ID: 24870807
I think this get them all. Its is a function that returns either true of false depending on if the url is valid


<script>
function testURL(url){
  if (!/blogspot.com$/i.test(url)) return false
  if  (/^(http:\/\/)?(www\.)?blogspot.com$/.test(url)) return false
  if  (/\w+\.blogspot.com$/.test(url)) return true
  return false
}
url="http://www.abc.blogspot.com"
alert(url+' '+testURL(url))
url="www.abc.blogspot.com"
alert(url+' '+testURL(url))
url="abc.blogspot.com"
alert(url+' '+testURL(url))
 
 
url="http://www.blogspot.com"
alert(url+' '+testURL(url))
url="http://www.abc.blogspot.com/sdfsf"
alert(url+' '+testURL(url))
url="http://www.abc.blogspot.in"
alert(url+' '+testURL(url))
url="fdsfsfsdf.com "
alert(url+' '+testURL(url))
</script>

Open in new window

0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 2000 total points
ID: 24870899
This is slightly better

<script>
function testURL(url){
  if (!/blogspot.com$/i.test(url)) return false
  if  (/^(http:\/\/)?(www\.)?blogspot.com$/i.test(url)) return false
  if  (/\w+\.blogspot.com$/i.test(url)) return true
  return false
}
</script>

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24871846
it work gr8..one thing forget to mention

the ending url can have /
i mean
www.dsd.blogspot.com/        (not compulsory but it can have)
www.dsd.blogspot.com (this is also correct ,but now if i entered www.dsd.blogspot.com/ 
 am getting false )


0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 2000 total points
ID: 24873302
try this
<script>
function testURL(url){
  if  (/^(http:\/\/)?(www\.)?blogspot.com$/i.test(url)) return false
  if  (/\w+\.blogspot.com\/?$/i.test(url)) return true
  return false
}
 
 
url="http://www.abc.blogspot.com"
alert(url+' '+testURL(url))
url="www.abc.blogspot.com"
alert(url+' '+testURL(url))
url="abc.blogspot.com"
alert(url+' '+testURL(url))
url="www.dsd.blogspot.com/"
alert(url+' '+testURL(url))
 
url="http://www.blogspot.com"
alert(url+' '+testURL(url))
url="http://www.abc.blogspot.com/sdfsf"
alert(url+' '+testURL(url))
url="http://www.abc.blogspot.in"
alert(url+' '+testURL(url))
url="fdsfsfsdf.com "
alert(url+' '+testURL(url))
</script>

Open in new window

0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 2000 total points
ID: 24873482
This is better I thought of some subcases you did not mention. eg  @!#$.abs.blogspot.com which should clearly fail

<script>
function testURL(url){
  if  (/^(http:\/\/)?(www\.)?blogspot.com\/?$/i.test(url)) return false
  if  (/^(http:\/\/)?(www\.)?\w+\.blogspot.com\/?$/i.test(url)) return true
  return false
}
</script>


0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24876181
Thanks ....:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

618 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