August 8th, 2013, 01:06 PM
File Upload Client Side Validation
I am using the following client side validation for a file upload to ensure selected file types only:
Now I'd like to prevent special characters, and add a max length of 20:
Although not fully tested yet, so far I have:
However, I have not yet figured out how to add the max length portion.
Any help would be greatly appreciated.
August 8th, 2013, 01:48 PM
If you don't mind 21 characters for .docx you can put a limit of 16 on the first part: +1 for period +3 for extension = 20.
Otherwise (a) use another regex or (b) a lookahead
August 8th, 2013, 03:13 PM
Thank you requinix. However, it does not pick up the max length validation. I can still upload files with names longer than 20 characters.
August 8th, 2013, 04:03 PM
August 8th, 2013, 04:36 PM
You are awesome. Thanks so much for the help!
August 12th, 2013, 05:55 AM
After some testing, I found that this denies all files when using Firefox.
Any additional suggestions?
August 12th, 2013, 06:52 AM
we can't tell you what's wrong if we don't know what your input looks like. For the test string 'abc\\test.jpg', the regex works perfectly in every browser I've tested (Firefox 22, Chrome 28 and IE 10).
You do realize that the regex expects a Windows-style backslash in the input?
August 13th, 2013, 02:32 PM
In Firefox 5, the upload path is C:\Upload\Test.docx
August 13th, 2013, 02:57 PM
Works for me.
["\\Test.docx", "Test", "docx"]
August 13th, 2013, 05:22 PM
I was incorrect. In Firefox, it is the file name only, and no path.
August 13th, 2013, 05:48 PM
Swap the leading slash with "a slash or the beginning of the string".