javascript - Regular expression always returning false in IE and Chrome -


I am using the following javascript to check that the file name contains only letters, numbers, dashes and underscores .

  var patt = /^[a-zA-Z0-9._- Aug. ++ /; If (! Patt.test (filename)) {Warning ("file names have illegal characters"); }  

Firefox works fine, filenames containing spaces are rejected and others are allowed, but in IE and Chrome, it always returns to the file, regardless of The file name should be passed to it.

I also tried to use the RexgExp object:

  var patt = new RegExp (/ ^ [a-zA-Z0-9 ._-] + $ /);  

But the result is the same.

Thanks to Everton Egner, I have passed the file name, and Chrome and IE have " C: \ falsepath \ "are added.

  var filename = filename.split ("\\")  

) .pop (); Var patt = /^[a-zA-Z0-9._- + Ag ++ /; If (! Patt.test (filename)) {Warning ("file names have illegal characters"); }


Comments