How to validate a filename in jQuery-Validation-Engine with no special characters allowed except for underscore (_
)?
I tried these regex: /^[a-zA-Z\d._]*$/
and /^[a-zA-Z0-9_]+$/
but no luck. The regex are valid based on https://regexr.com/
Here's my sample:
"validFileName": {
"regex": /^[a-zA-Z\d._]*$/,
"alertText": "* Invalid filename"
},
Input tag:
<input type="file" name="attachment" id="attachment" class="validate[required, custom[validFileName]]"/>