*EDIT**
i tried it with && instead of || and now it does not come back as false for any file. I do think it needs to be && though.
I have a custom validation function that I am using to check if the file is an excel file. When i test is the last 4 characters are .xls OR the last 5 characters are .xlsx it works but when i check for both it does not. Any idea why it will not let me do this?
$.validator.addMethod("xlsxOrxls", function(value, element) {
var isValid = true;
var xlsx = value.substr(value.length - 5);
var xls = value.substr(value.length - 4);
if (xls != '.xls' || xlsx != '.xlsx')
isValid = false;
return isValid;
}, "<br/><label style='color:red'><b>Not a valid file format.</b></label>"
);
If I comment out the var xlsx line and take out the “|| xlsx != ‘.xlsx'” part of the if statement it works and vice versa, but if i leave them both in there it will not work. I have even tried making them 2 separate functions but thats not working either.
Any idea why its not letting me do this?
Use regex instead!
Or, if you really want do do it your way: