I am wondering what this technique is called and what it does. It seems to be validating some regular expression on the variable url. I am customizing another persons code:
var url = document.getElementById("editorURL").value;
if(/(file|http).*/.test(url)) {
}
Maybe someone has a link to an article that explains this a bit more in-depth?
This is a regular expression checking whether
urlbegins with eitherfileorhttp, an effort to make sure the value entered is a proper URL pointing to a resource that can be opened in a browser.Seeing as it fails to check for the subsequent
://part (and would for example matchfilexyzorhttphttphttp), I would say it is not perfect.More on the
test()method at W3Schools.