I am trying to validate some urls in an application I have and found a function to do so. I can pass the URL and it will return true
or false
if the url is valid according to the regex.
While this is working for the typical everyday URLs, we have some urls that are on fileshares that we need to allow to pass validation.
I am trying to find out either a good pattern to use for fileshares that can be built into the function below or a jQuery plugin that me include this validation if this already exists.
alert(isURL('\\server-123.somedomain.com\path\to\file.txt')); // Returns False
function isURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return pattern.test(str);
}
Edit:
I don't need it to match that exact path structure in the example shown. I just need a pattern that allowed for file shares in general. My question is specific to the file share structure URL and not the typical http/s/ftp as mentioned as such in the suggested post here