Created
July 27, 2015 19:24
-
-
Save charitygrace/67a8caf91420ca18dabc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (?:^|\/|\\)(?:[a-zA-Z0-9\s\-\_])*\.[a-zA-Z]*$ | |
| This will check just the filename in a file upload and ignore the file path before the file name. | |
| This will allow any filename with letters, numbers, dashes, underscores and spaces. | |
| Use in jquery validator like this: | |
| $.validator.addMethod("fileName", function(value, element) { | |
| return this.optional(element) || /(?:^|\/|\\)(?:[a-zA-Z0-9\s\-\_])*\.[a-zA-Z]*$/.test(value); | |
| }, "File names can only contain letters, numbers, dashes, and underscores (and spaces)."); | |
| This post was helpful in determining how to ignore the file path before the file name: https://forum.jquery.com/topic/validate-a-filename-with-the-validation-pluging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment