Solved

need to validate blogspot url

Posted on 2009-07-16
10
290 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
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

 
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 500 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 500 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 500 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 500 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

696 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