I would like javascript detect the source of the image and take action regarding it is full URL or not with REGEX
Example Code:
var source = 'http://test.com/';
if( [if var source starting with http:// ] ){ // Regex conditional
// do something
}else{
// // something
}
How to do that with Javascript regex?
Thank you…
Here you go if you are adamant on Regex:
Javascript code to test here:
For your code:
But please note that this ONLY checks the first part of the URL, which may not necessarily mean that the rest of the string conforms to an URL. For e.g., your source string can be something like “http://^&#*@%.IAmABadUrl.com” which is not a valid URL if sent unencoded.
More about whats allowed in an URL on the IETF website: