Javascript URL validation
-
27-10-2019 - |
Question
I wrote a javascript validation script to validate if the URL contains '+' or whitespaces.
$.validator.addMethod("reportFileURL",
function(value,element){
if(((value.search(/[+]+/)) == -1)
&& ((value.search(/[ ]+/))) == -1){
return true;
}
},"Invalid filename");
Can i write the script more precise than this.
Solution
if (value.search(/[\s+]/) == -1) {
return true;
}
OTHER TIPS
return value.search(/[ +]/) == -1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow