I\'ve been searching all over for an answer to this and all of the answers I\'ve found haven\'t been in JavaScript.
I need a way, in javascript, to check if a string sta
Refining previous answers a bit more, I used new RegExp(...)
to avoid messy escapes, and also added an optional s
.
var pattern = new RegExp('^(https?|ftp)://');
if(!pattern.test(url)) {
url = "http://" + url;
}
var pattern = new RegExp('^(https?|ftp)://');
console.log(pattern.test('http://foo'));
console.log(pattern.test('https://foo'));
console.log(pattern.test('ftp://foo'));
console.log(pattern.test('bar'));