how to validate excel files
My JQuery
jQuery(\"#excel\").validate({
expression: \"if (VAL.match(/^([a-z]\\w*)\\.(xls[mx]?)$/) &am
You need to escape the dots.
^([a-z]\w*)(\.xlsx|\.xlsm|\.xls)$
OR
^([a-z]\w*)\.(xls[mx]?)$
[mx]?
matches an optional m
or x
Use this regex if you want to allow any characters inbetween ^([a-z].*)\.(xls[mx]?)$
First of all, you should change an order in expression, since you don’t want to execute expression on invalid VAL
:
VAL && VAL.match(/^([a-z]\w*)(.xlsx|.xlsm|.xls)
Secondary, any \w
symbol is perfectly valid as starting symbol for filename, as well, as a dot and space (and, possibly, some other symbols.) Dots in regexps should be escaped. And, a last but not least, you could want to compact the xls*
s:
/^([\w\s.]*)\.xls[xm]?$/