check if url is a root url [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm looking for a regex to test if a url is a root url:
http://site.org TRUE
http://www.example.com TRUE
...
http://www.example.com/dir FALSE
http://www.example.com/image.jpg FALSE
http://www.example.com/dir/file.doc FALSE

Try below regex will do the work
/^https?\:\/\/[^\/]+\/?$/
I tested like this:
var URL = "http://jsfiddle.net/";
var check =/^https?\:\/\/[^\/]+\/?$/.test(URL);
alert(check);
JSFiddle

try this:
var str='url...';
if(str.indexOf("/")<str.indexOf(".")&&(str.indexOf("http://")>-1))
return true;
else
return fals;

Try out with this regular expression
(?\w+)://(?[\w#][\w.:#]+)/?[\w.?=%&=-#/$,]*

Related

Javascript parse JSON string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Folks, DynamoDB call returns a JSON Object, which I would like to parse, and grab the password hash field
jsonString = JSON.stringify(data)
console.log(jsonString)
output:
{"Count":1,"Items":[{"token":{"S":"token"},"uid":{"S":"33c02130-66b5-11e3-bdb0-7d9889f293b5"},"password":{"S":"$2a$10$ervzJ.DWjHOXRtJSugTaWuquI2OvPLyipa4YXecc/2KdQnmhrHxr6"},"username":{"S":"foo"},"plate":{"S":"dinner"},"name":{"S":"Test Name"},"server":{"S":"bar"}}]}
How would i parse this string, and retrieve the 'password' field?
The following code does not work:
console.log(jsonString.password)
console.log(jsonString.uid)
The following returns undefined:
console.log(data.password);
Thanks!
This is already an object, so you can do this:
var str = {"Count":1,"Items":[{"token":{"S":"token"},"uid":{"S":"33c02130-66b5-11e3-bdb0-7d9889f293b5"},"password":{"S":"$2a$10$ervzJ.DWjHOXRtJSugTaWuquI2OvPLyipa4YXecc/2KdQnmhrHxr6"},"username":{"S":"foo"},"plate":{"S":"dinner"},"name":{"S":"Test Name"},"server":{"S":"bar"}}]};
alert(str.Items[0].password.S);

How can I convert this coffeescript to js/jquery? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
text = child.html()
text = text.replace /(#include(\s*<.*>)?)/gi, '<span>$1</span>'
text = text.replace /(main\(.*\))/gi, '<span>$1</span>'
child.html text
http://jsfiddle.net/dcro/XKHC8/
This is an answer from my question: Wrapping strings with a span I dont know how to use coffeescript and the one who answer looks unavailable.
From js2coffee.org
var text;
text = text.replace(/(#include(\s*<.*>)?)/gi, '<span>$1</span>');
text = text.replace(/(main\(.*\))/gi, '<span>$1</span>');
child.html(text);

Find a string in a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How would I write an if statement that alerts when the var MyString is not in the var URL?
var URL = "http://test.mysite.com/about/";
var MyString = "mysite.com";
if (URL.indexOf(MyString) === -1) {
alert('Not found!');
}
if(URL.indexOf(MyString) == -1) alert("Not found");

Adding an id on to a href jquery [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get the id of an radiobutton to be added to href when the link is clicked. I tried searching google for a long time. But maybe i'm missing because it's very basic.
I do have a bit of code written but it doesn't work. Help?
function ProductIDLink() {
var url = "/bbbb/aaaaaaa/" + ('.aaasaff:radio:checked').attr('id');
$("#safad").attr("href", url)
}
Looks like you've just forgotten a $:
... ('.aaasaff:radio:checked').attr('id')
should be
... $('.aaasaff:radio:checked').attr('id')
From what I can see the $ was missing.
function ProductIDLink() {
var url = "/bbbb/aaaaaaa/" + $('.aaasaff:radio:checked').attr('id');
$("#safad").attr("href", url)
}

JavaScript concatenate a variable into a constructor [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to concatenate a variable into a constructor in JavaScript
I have a variable like this:
var selectedLayer = "myLayer";
and then I am creating a Leaflet tile layer, I want to then incorporate the variable into the constructor:
test = new L.TileLayer.WMS('http://localhost/geoserver/wms',{layers : 'geonode:<selectedLayer>', format: 'image/png'});
string concatenation in javascript is done with the simple +, so your case would be:
{
layers: 'geonode:' + selectedLayer,
format: 'image/png'
}

Categories

Resources