need to validate blogspot url

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 ....
LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SaWeyCommented:
what characters are allowed in the username?
0
Rajar AhmedConsultantAuthor Commented:
characters which accepts blogspot website i think mostly alphanumeric .ll be fair enough..!
0
SaWeyCommented:
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Rajar AhmedConsultantAuthor Commented:
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
GwynforWebCommented:
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
GwynforWebCommented:
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
Rajar AhmedConsultantAuthor Commented:
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
GwynforWebCommented:
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
GwynforWebCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rajar AhmedConsultantAuthor Commented:
Thanks ....:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.