Regex validation code for excel file upload jQuery

前端 未结 2 1134
旧巷少年郎
旧巷少年郎 2021-01-27 06:29

how to validate excel files

My JQuery

 jQuery(\"#excel\").validate({
      expression: \"if (VAL.match(/^([a-z]\\w*)\\.(xls[mx]?)$/) &am         


        
2条回答
  •  一个人的身影
    2021-01-27 07:21

    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]?$/
    

提交回复
热议问题