Solved

need to validate blogspot url

Posted on 2009-07-16
10
284 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

867 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

26 Experts available now in Live!

Get 1:1 Help Now