Solved

need to validate blogspot url

Posted on 2009-07-16
10
281 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
  • 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now