Solved

need to validate blogspot url

Posted on 2009-07-16
10
287 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

726 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